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

Viewed 755

I'm trying to build a React Native Android application following an upgrade to RN 0.59.9, but I'm getting an error related to AndroidX.

I've tried many things including removing most native packages, changing AndroidManifest.xml and various other solutions mentioned on the internet but nothing seems to work.

My error is this:

> 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.

As I understand it means one of the package uses AndroidX but not the main app, however as far as I can tell nothing in my app uses AndroidX, and I made sure to upgrade to RN 0.59, not 0.60. I've even tried to grep "androidx" and remove all the packages that might mention it.

I've also tried to add "android.useAndroidX=true / android.enableJetifier=true" to gradle.properties just to see what happens but as expected many modules don't build since they have not been upgraded to AndroidX.

Any idea how to fix this bug?

1 Answers

This is most likely due to Android releasing all AndroidX libraries, and '+'-style gradle dependencies leaking in.

You can either ./gradlew :app:dependencies|grep androidx to find the problem libraries and then use gradle resolutionStrategies or android/build.gradle ext{} versioning to pin the Google library dependency, or you can convert your react-native project to androidx and use the jetifier tool via npm i jetifier && npx jetify so that non-androidx react-native libraries work.

Either should result in a working build as the react-native ecosystem transitions to AndroidX

Related