react-native打包apk常见错误收集

时间:2022-03-16 06:22:42

react-native 0.59打包报错,信息如下,根据错误信息是因为react-native-cookies的sdk版本问题导致的

 ./gradlew assembleRelease

 > Configure project :react-native-cookies
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (25.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.3.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools. > Configure project :react-native-webview
:react-native-webview:reactNativeAndroidRoot F:\WorkSpace\CP_HY\node_modules\react-native\android > Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
Loading dependency graph, done.
info Writing bundle output to:, F:\WorkSpace\CP_HY\android\app\build\generated\assets\react\release\index.android.bundle
info Done writing bundle output
info Copying 50 asset files
info Done copying assets > Task :react-native-cookies:verifyReleaseResources FAILED FAILURE: Build failed with an exception. * What went wrong:
Execution failed for task ':react-native-cookies:verifyReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.

根据错误信息,我们找到react-native-cookies下的andorid/build.gradle,修改skd版本如下

android {
compileSdkVersion 28 // 23 ->28
buildToolsVersion "28.0.3" // 25.0.2 -> 28.0.3 defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}

重新打包即可;

一般打包react-native应用时,最常见的错误就是第三方插件的sdk版本和react-native中android中的sdk版本不一致导致,这个时候不要慌,修改版本依赖,重新打包即可