尝试构建 React Native 0.59 应用程序时与 AndroidX 相关的 AndroidManifest 错误

AndroidManifest error related to AndroidX when trying to build React Native 0.59 app

升级到 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 .

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

这很可能是由于 Android 释放了所有 AndroidX 库,并且“+”式 gradle 依赖项泄漏。

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

当 react-native 生态系统过渡到 AndroidX

时,两者都应该会产生一个有效的构建