【react-native】0.57版本打包錯誤,SDK版本不匹配問題:Execution failed for task 'xxx:verifyReleaseResources'
阿新 • • 發佈:2018-12-17
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 }
然後重新發布就好了。