首页 > 解决方案 > React Native 在发布模式下崩溃

问题描述

当我运行react-native run-android --variant=release它时,它在模拟器和手机上不断崩溃,没有任何错误。

我尝试了本文中的建议,但是当我运行./gradlew clean && ./gradlew assembleRelease它时会出现此错误:

> Task :react-native-navigation:verifyReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':react-native-navigation:verifyReleaseResources'.

> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  /Users/balwindersingh/Desktop/WEBSITETOON/teamwallpaper/node_modules/react-native-navigation/android/app/build/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
  /Users/balwindersingh/Desktop/WEBSITETOON/teamwallpaper/node_modules/react-native-navigation/android/app/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
  /Users/balwindersingh/Desktop/WEBSITETOON/teamwallpaper/node_modules/react-native-navigation/android/app/build/intermediates/res/merged/release/values/values.xml:3083: error: resource android:attr/fontVariationSettings not found.
  /Users/balwindersingh/Desktop/WEBSITETOON/teamwallpaper/node_modules/react-native-navigation/android/app/build/intermediates/res/merged/release/values/values.xml:3084: error: resource android:attr/ttcIndex not found.

  error: failed linking references.

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 59s

180 actionable tasks: 168 executed, 12 up-to-date

标签: react-native

解决方案


问题可能是您正在使用 sdkVersion 28 构建您的应用程序,而 react-navigation 使用的是旧版本。

您可以覆盖android/build.gradle文件中的版本:

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion compileSdkVersion
                buildToolsVersion "$buildToolsVersion"
            }
        }
    }
}

ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 16
    compileSdkVersion = 28
    targetSdkVersion = 27
    supportLibVersion = "28.0.0"
}

(我不确定这是否是最好的方法......)

或者,您可以分叉 react-navigation 并将其android/app/build.gradle文件中的版本更改为28.


推荐阅读