简体   繁体   English

React Native Android Release Build失败 - Gradle

[英]React Native Android Release Build Failing - Gradle

I've got a rather complicated project some of which is older code from the past year or so which in React Native time is forever. 我有一个相当复杂的项目,其中一些是过去一年左右的旧代码,在React Native时间是永远的。 The regular debug build is working fine but the release build has errors. 常规调试版本工作正常,但发布版本有错误。 I've cobbled together answers from other places to make it as far as I have but I don't know how to get past this last bit. 我拼凑了其他地方的答案,尽我所能,但我不知道如何通过这最后一点。

I keep getting a bundling error where aapt will fail because it doesn't bundle the resources properly. 我一直收到捆绑错误,其中aapt会失败,因为它没有正确地捆绑资源。

Example of error code: 错误代码示例:

> 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

Building upon GenericJam's answer, you can do this programatically to all sub libraries by doing something like this in your project build.gradle file: 基于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
            }
        }
    }
}

The way to solve this that worked for me is to dive into the node_modules code for the supporting libraries that are triggering the error. 解决这个问题对我有用的方法是深入了解node_modules代码,以获取触发错误的支持库。

You will need to go into node_modules/project-name/android/build.gradle and change this 您需要进入node_modules / project-name / android / build.gradle并更改它

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    ...
}

to whatever the sdk version is in your /android/app/build.gradle is. 无论你的/droid/app/build.gradle中的sdk版本是什么。 For example: 例如:

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.1"
    ...
}

Hopefully this will be fixed in React Native so this workaround isn't necessary. 希望这将在React Native中修复,因此这种解决方法不是必需的。

Edit: I suspect Petter's solution is the better one although I haven't tried it myself. 编辑:我怀疑Petter的解决方案是更好的解决方案,虽然我自己没有尝试过。 Probably try that one first and if it doesn't work, try this next. 可能先尝试一下,如果不起作用,请尝试下一步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM