17

Working on a React Native project but out of sudden it stopped working & started giving an error:

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 AndroidManifest.xml:7:5-117 to override.

I know Google has done with Support Library class after 28 and I know How to migrate whole project from Support Library class to AndroidX class.

My question is:

  • Is there any possible way to keep using Support Library class rather than shifting to AndroidX class?

  • How to fix this issue?

Mohsin
  • 1,586
  • 1
  • 22
  • 44
  • 1
    Facing the same issue, also googles migration guide didn't work for me. Could you solve the compile error somehow? – Christoph Göttert Jun 18 '19 at 09:59
  • Yes, I just found the culprit 3rd party library in my code which is using Androidx support. If I remove it. My code start working. I think @pramod_m ans is somehow correct but this behaviour is not ok. It took me alot time to debug this issue. – Mohsin Jun 18 '19 at 10:17
  • How did you find out which 3rd party library was using Androidx? Currently in the same situation. – ThatsRight Jun 18 '19 at 10:36
  • You can use ```cd android && ./gradlew app:dependencies```to check which library is depending on androidx. Found this info on a [git-issue](https://github.com/facebook/react-native/issues/25292#issuecomment-502998885) related to these errors. – Christoph Göttert Jun 18 '19 at 11:07
  • For me it was serveral packages using androidx (e.g. react-native-device-info, react-native-push-notification, ...). The problem is that all packages which use a notation like this: ```compile 'com.google.android.gms:play-services-gcm:+'``` now use the latest support libraries, which use androidx since the [update from today](https://developers.google.com/android/guides/releases) (thank's google...). My solution for now will be to fork those libraries and set fix versions.. – Christoph Göttert Jun 18 '19 at 11:25
  • 2
    @ChristophGöttert I have the same issue as you, but there is an easier way to limit the version of play-services-gcm, add `googlePlayServicesVersion = "16.1.0"` or whatever version you are using to your build.gradle. No need to fork libs! – ThatsRight Jun 18 '19 at 12:09
  • 1
    I had the same issue and solved it using this: https://stackoverflow.com/a/56648987/8306924 – Udai Jun 18 '19 at 12:20

5 Answers5

5

You can lock down your googleservices and firebase versions to avoid androidX.

In android/build.gradle add:

buildscript {
  ...
  ext {
    // Lock down googlePlayServicesVersion
    googlePlayServicesVersion = "16.1.0"
    firebaseVersion = "17.6.0"
  }
}

OR in gradle.properties add:

googlePlayServicesVersion=16.1.0
firebaseVersion=17.6.0
chenop
  • 4,743
  • 4
  • 41
  • 65
A-J-A
  • 2,344
  • 1
  • 17
  • 26
4

Probably post your app level gradle file here. Ideally if you are using some other dependency which is the updated/latest one then you would get this error.

If any of the dependency is the latest/updated one please downgrade it to the lesser version from checking the change logs from it's github. For me the culprit was stripe version which was internally using the androidx and was getting this error. i downgraded it and boom! It's gone :)

And also disable the androidx from gradle.properties file using

android.useAndroidX=false
android.enableJetifier=false

Which forces the androidx to be disabled.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
pramod_m
  • 184
  • 1
  • 9
  • Yes, I agree this is the trouble as I have many module (dependencies) which I have linked with my root project from node_modules folder. Dun know what is best to do! :/ – Mohsin Jun 18 '19 at 08:53
  • Check with your app level build.gradle file – pramod_m Jun 18 '19 at 09:03
  • According to documentation useAndroidX & enableJetifier are by default: false So this is not a case – Mohsin Jun 18 '19 at 09:11
  • In my case, I tried to `./gradlew :[module]:dependencies | grep "[androidx libs]"` to find which one my current 3rd-party library that has transitive/dependent to `androidx` library, then force it to use `android-support` version or `exclude` it. – mochadwi Feb 26 '20 at 10:59
  • 1
    After much frustration this solved the problem for me - Thanks @pramod_m – Chris Noldus Mar 02 '20 at 22:32
2

According from Dan Lew

The support library artifacts are being deprecated and all future development is going into AndroidX, so there's no avoiding this migration. Hopefully, though, these tips will give you a clearer transition path.

Wiguna R
  • 157
  • 5
  • 19
2

Is there any possible way to keep using Support Library class rather than shifting to AndroidX class?

Yes it is possible, but you can only postpone this event.
You can't avoid it.

The new Firebase libraries and the new Google Play Libraries require androidx (check the lists below)

In a short time other third libraries will use these dependencies.

How to fix this issue?

You can only use the last versions of firebase/google play services/third libraries that work with support libraries v.28 or below.

Here the list of firebase and google play services libraries which started to work with the dependency of androidx.

Firebase:

Ads version 18.0.0
Analytics version 17.0.0
App Indexing version 19.0.0
Authentication version 18.0.0
Cloud Firestore version 20.0.0
Cloud Firestore-ktx version 20.0.0
Cloud Functions (client) version 18.0.0
Cloud Messaging version 19.0.0
Cloud Storage version 18.0.0
Dynamic Links version 18.0.0
In-App Messaging version 18.0.0
In-App Messaging Display version 18.0.0
Instance IDs version 19.0.0
ML Kit Common version 20.0.0
ML Kit Vision version 21.0.0
ML Kit Image Labeling Model version 18.0.0
ML Kit Face Detection Model version 18.0.0
ML Kit Object Detection and Tracking Model version 17.0.0
ML Kit Vision AutoML version 17.0.0
ML Kit Natural Language version 20.0.0
ML Kit Language Identification Model version 20.0.0
ML Kit Smart Reply Model version 20.0.0
ML Kit Translate Model version 20.0.0
ML Kit Model Interpreter version 20.0.0
Realtime Database version 18.0.0
Performance Monitoring version 18.0.0
Remote Config version 18.0.0
A/B Testing version 18.0.0

Play services libraries:

com.google.android.datatransport:transport-api:2.0.0
com.google.android.datatransport:transport-backend-cct:2.0.0
com.google.android.datatransport:transport-runtime:2.0.0
com.google.android.gms:play-services-ads:18.0.0
com.google.android.gms:play-services-ads-identifier:17.0.0
com.google.android.gms:play-services-ads-lite:18.0.0
com.google.android.gms:play-services-afs-native:17.0.0
com.google.android.gms:play-services-analytics:17.0.0
com.google.android.gms:play-services-analytics-impl:17.0.0
com.google.android.gms:play-services-appinvite:18.0.0
com.google.android.gms:play-services-audience:17.0.0
com.google.android.gms:play-services-auth:17.0.0
com.google.android.gms:play-services-auth-api-phone:17.0.0
com.google.android.gms:play-services-awareness:17.0.0
com.google.android.gms:play-services-base:17.0.0
com.google.android.gms:play-services-basement:17.0.0
com.google.android.gms:play-services-cast:17.0.0
com.google.android.gms:play-services-cast-framework:17.0.0
com.google.android.gms:play-services-clearcut:17.0.0
com.google.android.gms:play-services-cronet:17.0.0
com.google.android.gms:play-services-drive:17.0.0
com.google.android.gms:play-services-fido:18.0.0
com.google.android.gms:play-services-fitness:17.0.0
com.google.android.gms:play-services-flags:17.0.0
com.google.android.gms:play-services-games:18.0.0
com.google.android.gms:play-services-gass:18.0.0
com.google.android.gms:play-services-gcm:17.0.0
com.google.android.gms:play-services-identity:17.0.0
com.google.android.gms:play-services-iid:17.0.0
com.google.android.gms:play-services-instantapps:17.0.0
com.google.android.gms:play-services-location:17.0.0
com.google.android.gms:play-services-maps:17.0.0
com.google.android.gms:play-services-measurement:17.0.0
com.google.android.gms:play-services-measurement-api:17.0.0
com.google.android.gms:play-services-measurement-impl:17.0.0
com.google.android.gms:play-services-measurement-sdk:17.0.0
com.google.android.gms:play-services-measurement-sdk-api:17.0.0
com.google.android.gms:play-services-nearby:17.0.0
com.google.android.gms:play-services-oss-licenses:17.0.0
com.google.android.gms:play-services-panorama:17.0.0
com.google.android.gms:play-services-phenotype:17.0.0
com.google.android.gms:play-services-places:17.0.0
com.google.android.gms:play-services-places-placereport:17.0.0
com.google.android.gms:play-services-plus:17.0.0
com.google.android.gms:play-services-safetynet:17.0.0
com.google.android.gms:play-services-stats:17.0.0
com.google.android.gms:play-services-tagmanager:17.0.0
com.google.android.gms:play-services-tagmanager-api:17.0.0
com.google.android.gms:play-services-tagmanager-v4-impl:17.0.0
com.google.android.gms:play-services-tasks:17.0.0
com.google.android.gms:play-services-vision:18.0.0
com.google.android.gms:play-services-vision-common:18.0.0
com.google.android.gms:play-services-vision-image-label:18.0.0
com.google.android.gms:play-services-wallet:17.0.0
com.google.android.gms:play-services-wearable:17.0.0
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • How about old Android devices? Like v4.x – Yousha Aleayoub Oct 08 '19 at 19:14
  • Androidx migration is not related to a change of the min sdk required. Obviously libraries improve and sooner or later the min sdk will increase. In any case 4.x is a quite big range and we are talking about [2012-2013](https://developer.android.com/studio/releases/platforms) (6 years ago!) and with a current [distribution <10%](https://developer.android.com/about/dashboards) – Gabriele Mariotti Oct 08 '19 at 19:22
  • Services with versions mentioned in this answer already work with androidX. If needed pre-androidX, try 16.0.0. Worked in my case – Dmitriy Pavlukhin Oct 10 '19 at 16:52
  • @DmitriyPavlukhin I wrote in the answer: *The new Firebase libraries and the new Google Play Libraries require androidx (check the lists below)*. All the versions reported work with androidx. In any case, thanks for the feedback, I will try to highlight better this point. – Gabriele Mariotti Oct 10 '19 at 18:10
2

You mention you are using react-native. As mentioned elsewhere you cannot avoid AndroidX for ever though you may postpone it.

In react-native particularly it was difficult to convert because gradle does not jetify source files except for during the original refactor via Android Studio, and react-native ships it's native code as source files.

Now you may simply use the 'jetifier' tool though, and after installing it and running it the first time add npx jetify in the postinstall of your package.json for persistent jetification across node module installs/updates.

Then you should be able to successfully convert your app to AndroidX, start depending on new AndroidX library versions but still use libraries that have not converted. You will be better prepared for react-native 0.60 which will be AndroidX

If you must postpone AndroidX and are using react-native, for react-native 0.59 at least, you may also use the jetifier tool in reverse to modify source references in node_modules from androidx to the compat references.

Mike Hardy
  • 2,274
  • 3
  • 25
  • 57
  • Note that jetifier was incorporated as a default step in `react-native start`, so if that is a normal part of your workflow you are now actually getting this behavior by default and you should be able to almost fearlessly upgrade to AndroidX dependencies. Cheers – Mike Hardy Sep 04 '19 at 16:36