58

I started to get this error today, yesterday everything worked fine, there was no changes in gradle or firebase version

The library com.google.firebase:firebase-iid is being requested by various other libraries at [[17.0.0,17.0.0]], but resolves to 16.2.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

I saw that yesterday was update in google-services plugin, probably that is causing the problem.

How to fix this problem?

Lucky_girl
  • 4,543
  • 6
  • 42
  • 82
  • 1
    Update all your firebase implementation versions and your project build.gradle file with the newest google-services version – Jacob Celestine Aug 14 '18 at 11:08
  • Check if you has OneSignal in your app. If you do, refer to this https://stackoverflow.com/questions/46552044/how-to-fix-the-error-cannot-change-strategy-of-configuration-in-gradle/50948594#50948594 – jujka Aug 14 '18 at 11:24
  • @GeorgySavatkov I don't have OneSignal in this project – Lucky_girl Aug 14 '18 at 11:26
  • 2
    Oh well. Then you might actually wanna execute `./gradlew :app:dependencies` and see what's going on. Another tip: in your both app and module level `gradle` file make sure that `google()` is at the very top and `jcenter()` is at the very bottom of `repositories` section. Ridiculously, sometimes it helps – jujka Aug 14 '18 at 11:29
  • I have fixed similar issue with [this](https://stackoverflow.com/a/52496742/2131915) – raghu Sep 25 '18 at 11:14
  • @egorikem : `./gradlew :app:dependencies` isn't showing anyone referring to the version its resolving to. `configurations.all { resolutionStrategy { force 'com.google.firebase:firebase-iid:17.0.2' } } ` isn't working either. – Kira Oct 04 '18 at 06:59
  • Latest version of firebase and Play services - https://stackoverflow.com/a/52696667/3333878. If this fix doesn't work or you have many dependencies and can't find which is causing this issue, then try to comment/uncomment each firebase or play services dependency, and syncing gradle one after another. Until you find the package that is causing the problem, then you can update that package version – abitcode Nov 09 '18 at 08:09

19 Answers19

44

I had the same issue. A quick fix would be to disable the strict version checking that is causing this problem. Add

com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

at the very bottom of your app build.gradle file.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Nick
  • 496
  • 5
  • 4
  • 28
    I guess there could be some bad side-effects from this? – Oliver Dixon Oct 21 '18 at 17:56
  • 1
    This may seem dangerous, but I've tried all the answers on this page, nothing works except this one. Our project just stopped compiling over the weekend without any changes made by us and it's preventing us doing a new release – what else can we do?! – chichilatte Feb 25 '19 at 11:51
  • Better check (and upvote) @masoudmjm solution. It's a better one, because no need to disable any Checks. The main-issue might be that you miss to update other rnFirebase Plugins you use (e.g. Messaging). For me it solved to put firebase-messaging to 17.5.0 like described in the Docs on rnfirebase. – suther Apr 29 '19 at 13:05
  • Hi @Nick, (or anyone else who could answer): When using cordova the build.gradle is created in runtime, you cannot add anything to it, only option is to use build-extras. Is there a way to add this rule to build-extras.gradle ? – zi88 Jul 13 '19 at 22:39
  • 7
    Not working for me. I get this: `No such property: config for class: com.google.gms.googleservices.GoogleServicesPlugin` – Jonathan Aug 08 '19 at 16:59
36

I had the same issue. I solved it by updating firebase messaging to the latest version(at this time).

implementation 'com.google.firebase:firebase-messaging:17.0.0'

to

implementation 'com.google.firebase:firebase-messaging:17.3.4'

and it is resolved(without side effect)

Abhishek Kumar
  • 4,532
  • 5
  • 31
  • 53
masoud jafari
  • 522
  • 9
  • 14
  • 1
    Same thing I tried, and it worked. This should be upvoted, as the current best answer is recommending something which might cause other side-effects later on. – harkirat1892 Jan 26 '19 at 09:34
  • Worked for me, had to update to `implementation 'com.google.firebase:firebase-messaging:17.6.0'` – ryzhak Apr 22 '19 at 11:29
  • That is the right solution. If you upgrade rnfirebase, keep in mind to update all used firebase-Components too!!! For this, check the "Install"-Section of each rnFirebase Plugin you use. – suther Apr 29 '19 at 13:03
  • This is the correct answer. Please don disable any checking – amar Sep 03 '19 at 07:50
  • I had to update this in project.properties because build.gradle kept resetting – Jake May 04 '20 at 15:07
30

If you had this problem you might see a lot of posts saying that you can disable this check. I don't like doing that because it hides the problem.

After a while I finally understood it was saying that some library was asking for a version I didn't have. So I added this in the build/app/build.gradle and it built

implementation "com.google.firebase:firebase-iid:17.0.2"

Just use the version it says it resolves to, in your case 16.2.0.

Daud Arfin
  • 2,499
  • 1
  • 18
  • 37
sebastianf182
  • 9,844
  • 3
  • 34
  • 66
  • 4
    Thank you. This was the solution in my situation. There was an update from 'com.google.firebase:firebase-messaging:21.1.0' to ':22.0.0'. Before this implementation statement was sufficient. But now I had to add 'com.google.firebase:firebase-iid:21.1.0'. I don't know why, but with it the project builds without error again. Unfortunately the error message "Duplicate class" is very confusing! – Harald Mandl May 17 '21 at 07:26
21

For me disabling version check did not solve the problem. What I did is to exclude firebase-iid module from firebase messaging library and add it separately

implementation ("com.google.firebase:firebase-messaging:17.3.4"){
        exclude group: 'com.google.firebase', module: 'firebase-iid'
    }

implementation 'com.google.firebase:firebase-iid:17.0.3'
Ana Koridze
  • 1,532
  • 2
  • 18
  • 28
7

I had a similar error with 'com.google.firebase:firebase-iid using these firebase dependencies:

  1. implementation 'com.google.firebase:firebase-core:16.0.7'
  2. implementation 'com.google.firebase:firebase-messaging:17.3.4'
  3. implementation 'com.google.firebase:firebase-database:16.0.6'
  4. implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6'
  5. implementation 'com.google.firebase:firebase-functions:16.1.3'

after adding

  • implementation 'com.google.firebase:firebase-analytics:16.3.0'

it went away.

Aris Bartee
  • 728
  • 8
  • 12
5

I got the same error today. I'm using react-native-firebase and react-native-push-notification. Running ./gradlew :app:dependencies I saw that react-native-push-notification was requiring the latest version of com.google.firebase:firebase-messaging, which in turn was requiring com.google.firebase:firebase-iid:[17.0.0], causing the error.

I manually specified an earlier version of firebase-messaging for react-native-push-notification as described here. That fixed the problem for me:

// in android/build.gradle

ext {
    firebaseVersion = '17.1.0' // add this line
    // ...
}
  • Swigget do you need to install react-native-firebase to get react-native-push-notifications to work from FCM ? – AleXzpm Sep 15 '18 at 06:33
3

This solved mine. So you can try it out. Add

googleServices { disableVersionCheck = true }

to app\build.gradle

Mr Strange
  • 666
  • 6
  • 4
  • What's the downside of this? – devmike01 Nov 21 '19 at 11:57
  • Well i none that i have noticed, but certainly it means dependencies that won't function based on some outdated versions will not be picked up by gradle since it no longer checks the version. But since we specify Googleservices shouldn't be too huge a compromise. – Mr Strange Nov 22 '19 at 20:34
3

I think I am late here to answer this but maybe this solution will solve someone's problem.

In build.gradle updating com.google.gms:google-services:4.0.0to com.google.gms:google-services:4.3.3 solved my issue.

Pratik Sanap
  • 107
  • 8
2

For me it was the build.gradle file in node_modules/@aws-amplify/pushnotification (the same applies for the build.gradle file in react-native-push-notification)

change the version numbers of firebase packages to match what you have in your own app/build.gradle file.

For me that was

compile 'com.google.firebase:firebase-messaging:17.6.0' compile 'com.google.firebase:firebase-core:16.0.8'

MattDameon
  • 31
  • 1
2
  • add the latest cordova-android platform (v8.0.0)

    ionic cordova platform add android@latest

  • add my fork of this plugin

    ionic cordova plugin add cordova-plugin-firebasex

  • add plugin to enable AndroidX in the project

    ionic cordova plugin add cordova-plugin-androidx

  • add plugin to patch existing plugin source

ionic cordova plugin add cordova-plugin-androidx-adapter

  • build!

    ionic cordova build android

It's 100% works

Yogesh Kumar
  • 1,016
  • 11
  • 10
2

For Android Studio Users Only

I had the same issue. and this is added after apply plugin: 'com.google.gms.google-services' com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

at the very bottom of your app build.gradle file and my problem was solved

 apply plugin: 'com.google.gms.google-services' 

com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
2

I updated my firebase messaging version and it solved my problem.

Before

implementation 'com.google.firebase:firebase-messaging:17.6.0'

updated

implementation 'com.google.firebase:firebase-messaging:20.0.1'

Rajeev Shetty
  • 1,534
  • 1
  • 17
  • 27
2

While I was setting up FCM android client from Android Studio assistant, and it was somehow only adding some old versions of fcm in my gradle file, I copy pasted exact-latest version from the android developers website itself, Then the error went on its own. Hope this helps someone facing similar issue.

nobalG
  • 4,544
  • 3
  • 34
  • 72
1

I had the same issue but I solved it by updating all my firebase dependencies to the latest ones.

// Firebase
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'

    implementation 'com.firebaseui:firebase-ui-firestore:5.0.0'
    implementation 'com.firebaseui:firebase-ui-storage:5.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.3.0-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
EngineerDanny
  • 795
  • 1
  • 9
  • 13
1

I had a similar issue, but with the error message;

Dependency failing: com.google.firebase:firebase-messaging:17.0.0 -> com.google.firebase:firebase-iid@[16.0.0], but fire base-iid version was 19.0.0.

and resolved it by using the following versions in App-level build.gradle;

// Google Firebase
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
functup
  • 43
  • 5
  • I had a similar issue and just changed the com.google.firebase-messaging to version 19.0.0 and worked fine.Just a heads up – wanjiku Aug 30 '19 at 03:31
1

I got the same issue when integrating 'firebase-analytics'.

Original code:

implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-analytics:17.0.0'

Solved by code:

implementation 'com.google.firebase:firebase-core:16.0.4 '
implementation 'com.google.firebase:firebase-analytics:16.0.0'

change the 'firebase-analytics' version the same level with 'firebase-core'

Kshitij Saxena
  • 930
  • 8
  • 19
Eason
  • 11
  • 3
1

The version increase of firebase-messaging is essentially correct, but just in case people see this going forward, I recommend seeing Current Android Release Notes to keep all of your firebase libraries up to date.

The issue is that if you implement one library that requires other Firebase libraries to run, and you add a second with the same dependencies but on later versions, you lose compatibility.

As of present time, Google has gotten much better at not releasing breaking or incompatible versions of new libraries. Use the latest of each and you should be fine.

Wes Winn
  • 551
  • 5
  • 15
0

If upgrading all the com.google.firebase libraries doesn't fix the issue, try upgrading the google services plugin dependency at com.google.gms:google-services.

alexfdz
  • 435
  • 4
  • 5
0

I got the same issue. Issue resolved by updating latest firebase-messaging version from https://firebase.google.com/support/release-notes/android

From

implementation 'com.google.firebase:firebase-messaging:19.0.0'

to

implementation 'com.google.firebase:firebase-messaging:19.0.1'

I do not know why build error was occurring all on a sudden. It seems weird but When I updated the firebase-messaging version, issue resolved.

Saidur Rahman
  • 546
  • 2
  • 4
  • 20