[英]React Native Android Release Build Failing - Gradle
我有一個相當復雜的項目,其中一些是過去一年左右的舊代碼,在React Native時間是永遠的。 常規調試版本工作正常,但發布版本有錯誤。 我拼湊了其他地方的答案,盡我所能,但我不知道如何通過這最后一點。
我一直收到捆綁錯誤,其中aapt會失敗,因為它沒有正確地捆綁資源。
錯誤代碼示例:
> Task :app:bundleReleaseJsAndAssets
Scanning folders for symlinks in /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/node_modules (9ms)
Scanning folders for symlinks in /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/node_modules (6ms)
warning: the transform cache was reset.
Loading dependency graph, done.
bundle: Writing bundle output to: /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/android/app/build/intermediates/assets/release/index.android.bundle
bundle: Done writing bundle output
error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:9:5-12:13: AAPT: error: resource android:attr/colorError not found.
/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:13:5-16:13: AAPT: error: resource android:attr/colorError not found.
/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:17:5-93: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
error: failed linking references.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-image-resizer:verifyReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
基於GenericJam的答案,您可以通過在項目build.gradle
文件中執行類似的操作,以編程方式對所有子庫執行此操作:
subprojects { subproject ->
afterEvaluate{
if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
解決這個問題對我有用的方法是深入了解node_modules代碼,以獲取觸發錯誤的支持庫。
您需要進入node_modules / project-name / android / build.gradle並更改它
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
...
}
無論你的/droid/app/build.gradle中的sdk版本是什么。 例如:
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
...
}
希望這將在React Native中修復,因此這種解決方法不是必需的。
編輯:我懷疑Petter的解決方案是更好的解決方案,雖然我自己沒有嘗試過。 可能先嘗試一下,如果不起作用,請嘗試下一步。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.