首页 > 解决方案 > 尝试构建 React Native 0.59 应用程序时与 AndroidX 相关的 AndroidManifest 错误

问题描述

我正在尝试在升级到 RN 0.59.9 后构建一个 React Native Android 应用程序,但我收到了与 AndroidX 相关的错误。

我尝试了很多方法,包括删除大多数本机软件包、更改 AndroidManifest.xml 以及互联网上提到的各种其他解决方案,但似乎没有任何效果。

我的错误是这样的:

> Task :app:processReleaseManifest FAILED
....\android\app\src\main\AndroidManifest.xml:22:18-91 Error:
        Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:35:2-108:16 to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.


FAILURE: Build failed with an exception.

据我了解,这意味着其中一个包使用 AndroidX,但不是主应用程序,但据我所知,我的应用程序中没有任何内容使用 AndroidX,我确保升级到 RN 0.59,而不是 0.60。我什至尝试 grep "androidx" 并删除所有可能提到它的包。

我还尝试将“android.useAndroidX=true / android.enableJetifier=true”添加到 gradle.properties,只是为了看看会发生什么,但正如预期的那样,许多模块没有构建,因为它们还没有升级到 AndroidX。

知道如何修复这个错误吗?

标签: androidreact-nativebuildandroidx

解决方案


这很可能是由于 Android 发布了所有 AndroidX 库,并且 '+' 样式的 gradle 依赖项泄漏。

您可以./gradlew :app:dependencies|grep androidx找到问题库,然后使用 gradle resolutionStrategies 或 android/build.gradle ext{} 版本控制来固定 Google 库依赖项,或者您可以将您的 react-native 项目转换为 androidx 并使用 jetifier 工具,npm i jetifier && npx jetify这样非-androidx react-native 库工作。

随着 react-native 生态系统过渡到 AndroidX


推荐阅读