DEV Community

JulietteR
JulietteR

Posted on • Originally published at Medium on

Tutorial: How to Fix a Failing Android Build Due to [androidx.core:core:1.0.0] Issues (June 2019)

Photo by Johnny Wharris

If you’re a React Native developer like me, you may have been surprised to see your Android build that JUST WORKED, failing and failing and failing again.

The issue, if you’re in Android Studio, went something like this:

Caused by: java.lang.RuntimeException: Manifest merger failed : 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 manifestMerger6369655802117611865.xml:7:5–9:19 to override.

Did you think to yourself “Huh? AndroidX? I’m not supporting that yet.”, then follow along. Here’s how to fix the issue without adding AndroidX support.

What Happened?

Google pulled a fast one on us yesterday (June 17, 2019) and released a MAJOR version update on it’s Google Play and Firebase libraries. That means, any dependencies imported to the tune of:

implementation com.google.android.gms:play-services-base:+

…(note the +) will be affected.

How to Fix It

1) Hop over to your /android/app/build.gradle file and check out your dependencies. Search for any instance of play-services or firebase* and see if it’s pulling in the latest version (+).

dependencies {
  implementation "com.android.support:appcompat-v7...
  implementation "com.facebook.react:react-native:+"
  // found one! vv
  implementation "com.google.android.gms:play-services-base:+"
  // found one! vv
  implementation "com.google.android.gms:play-services-maps:+"
  implementation "com.google.firebase:firebase-core:16.0.1"
}

2) Head over to MVNRepository and search for the troublesome dependencies. Here you’ll be able to find the last released version of your module. Update /android/app/build.gradle to that version along with a force flag to handle any version conflicts:

dependencies {
 implementation "com.android.support:appcompat-v7..
 implementation "com.facebook.react:react-native:+"
 implementation ("com.google.android.gms:play-services-base:16.1.0"){ force = true }
 implementation ("com.google.android.gms:play-services-maps:16.1.0"){ force = true }
 implementation "com.google.firebase:firebase-core:16.0.1"
}

3) Time to handle your node_modules. Navigate into /android and run the following command:

./gradlew :app:dependencies

This will generate a dependency tree for your entire project.

4) Grab the tree and paste in into a text editor. Search for any instance of play-services or firebase* and navigate up the tree to see where the module is being used. In this case, react-native-push-notifications has a com.google.android.gms:play-services-gcm:+ dependency.

+ — — project :react-native-push-notification
 | + — — com.android.support:appcompat-v7:28.0.0 (\*)
 | + — — com.facebook.react:react-native:+ -\> 0.59.8 (\*)
 | + — — com.google.android.gms:play-services-gcm:+ -\> 17.0.0 (\*)
 | + — — me.leolin:ShortcutBadger:1.1.8

5) Patch those packages! If I am in a time crunch, I will use patch-package, a genius library that lets you make changes to a package and then creates a patch for you to store with your project. The patch will then apply via a postinstall any time you or someone on your team runs npm i.

In my case, I navigated to the build.gradle file of react-native-push-notification, made my updates, ran:

npx patch-package react-native-push-notification

…and voila! I have a patch!

And You’re Done!

In my case, I needed to apply patches to both react-native-push-notification and react-native-push-notification.

Do note that this is just a band-aid until you’re ready to support AndroidX and all its glory 🤖

Hope this helps!

*For a full list of updated dependencies navigate here.


👋 Hi! I’m Juliette. I work at Eventric as a Software Developer. Come follow me on Twitter at @Juliette.

Top comments (0)