android - React Native Android 发布构建失败 - 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
}
}
}
}
推荐阅读
- ssl - 我需要按顺序导入 SSL 链吗?
- kubernetes - kubernetes default-scheduler 不应该尊重已达到--max-pods 的节点吗?
- php - 无法解决在同一张表中有数据的sql查询
- regex - 无法正确获取 perl 多行替换
- google-chrome - 如何在 ubuntu 16.04 中安装邮递员客户端
- wpf - 如果 WPF 中的数据过多,如何使网格视图中显示的数据自动转到第二列
- angular - Angular 中的 Firebase 和 ng2-ion-range-slider 包冲突
- java - 扩展 Eclipse 通用文本编辑器
- java - 使用分页和多个过滤器为数据库查询构建 GET Rest API
- autocad-plugin - 在 AutoLISP 的特定索引中更改 DXF 实体