我有一个相当复杂的项目,其中一些是过去一年左右的旧代码,在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
答案 0 :(得分:16)
基于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
}
}
}
}
答案 1 :(得分:13)
解决这个问题的方法对我来说很有效,那就是深入研究引发错误的支持库的node_modules代码。
您将需要进入node_modules / project-name / android / build.gradle并进行更改
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
...
}
到/android/app/build.gradle中的sdk版本。 例如:
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
...
}
希望这将在React Native中修复,因此不需要此解决方法。
编辑:我怀疑Petter的解决方案是更好的解决方案,尽管我自己还没有尝试过。可能先尝试一个,如果不起作用,请尝试下一个。