【react-native】0.57版本打包错误,SDK版本不匹配问题:Execution failed for task 'xxx:verifyReleaseResources'

react-native版本:0.57.1

这个问题原本不是rn版本的问题,原因是0.57.1将Android SDK的版本更新到27了,这与大多第三方使用了原生代码的插件不兼容了,因为第三方更新不及时,SDK还是旧的版本。

先来看下错误日志: 

error: invalid file path 'D:\xxx\node_modules\react-native-version-number\android\build\intermediates\manifests\aapt\release\AndroidManifest.xml'.

> Task :react-native-version-number:verifyReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-version-number:verifyReleaseResources'.
> java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 3m 22s
156 actionable tasks: 16 executed, 140 up-to-date

这个是只有打包apk时才会出现的错误,需要注意两个地方来确定你的错误和我遇到的是同一类错误:

1."verifyReleaseResources"

2."Aapt2Exception"

解决方案:

1.首先在node_modules中找到报错的包里面的build.gradle,比如我这个就是\node_modules\react-native-version-number\android\build.gradle;

2.修改这个build.gradle,使其与android/build.gradle(也可能是android/app/build.gradle)里面的SDK版本保持一致;

3.将build.gradle里的compile改为implementation,因为compile已过时。

android {
    compileSdkVersion 27 // 23 -> 27
    buildToolsVersion "27.0.3" // 23.0.1 -> 27.0.3

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26 // 22 -> 26
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    lintOptions {
       warning 'InvalidPackage'
    }
}

dependencies {
    implementation 'com.facebook.react:react-native:+' // compile -> implementation
}

然后重新发布就好了。

猜你喜欢

转载自blog.csdn.net/danding_ge/article/details/83380657