应用程序在升级targetSdk版本时崩溃

时间:2019-11-22 12:09:46

标签: android react-native gradle react-native-android

Play商店现在要求您的应用使用API​​级别28:

  

新应用程序和应用程序更新都必须至少针对Android 9(API级别28)。

Source

我的应用当前正在使用targetSdkVersion = 26进行以下配置:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        googlePlayServicesAuthVersion = "15.0.1"
        googlePlayServicesVersion = "15.0.1"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}

/**
* Project-wide gradle configuration properties for use by all modules
*/
ext {
    compileSdkVersion               = 28
    targetSdkVersion                = 28
    buildToolsVersion               = "28.0.3"
    googlePlayServicesVersion       = "12.0.1"
    googlePlayServicesVisionVersion = "15.0.2"
    supportLibVersion               = "28.0.0"
}
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                && !details.requested.name.contains('multidex') ) {
            details.useVersion "28.0.0"
            }
        }
    }
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 28
                buildToolsVersion '28.0.3'
            }
        }
    }
}

尝试解决此问题,我已更改为:

ext {
    compileSdkVersion               = 28
    targetSdkVersion                = 28
    buildToolsVersion               = "28.0.3"
    googlePlayServicesVersion       = "12.0.1"
    googlePlayServicesVisionVersion = "15.0.2"
    supportLibVersion               = "28.0.0"
}

该应用似乎可以在我们拥有Android 6.0的设备上正常运行,但是在其他设备(如Android 9)中,该应用一开始崩溃,并抛出错误消息:

Android print

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

请遵循以下命令:

1. cd android/ && ./gradlew clean && cd ..

2. react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

3. react-native run-android

让我知道是否仍然面临同样的问题