React-native-fcm: More than one library with package name 'com.google.android.gms.license'

Created on 21 Mar 2018  ·  57Comments  ·  Source: evollu/react-native-fcm

During the build I received this error message:

Execution failed for task ':react-native-fcm:processReleaseResources'.

Error: more than one library with package name 'com.google.android.gms.license'

Most helpful comment

Add config in android/build.gradle

...
allprojects {
    repositories {
        ...
        configurations.all {
            resolutionStrategy {
                // Add force (11.4.0 is version you want to use)
                force 'com.google.firebase:firebase-messaging:11.4.0'
                force 'com.google.firebase:firebase-core:11.4.0'
                force 'com.google.android.gms:play-services-gcm:11.4.0'
            }
        }
    }
}

All 57 comments

Add config in android/build.gradle

...
allprojects {
    repositories {
        ...
        configurations.all {
            resolutionStrategy {
                // Add force (11.4.0 is version you want to use)
                force 'com.google.firebase:firebase-messaging:11.4.0'
                force 'com.google.firebase:firebase-core:11.4.0'
                force 'com.google.android.gms:play-services-gcm:11.4.0'
            }
        }
    }
}

Thank @sy92th . It Worked for Me

@sy92th it worked for me too, but I use 11.8.0 so yeah

@sy92th It worked for me too.
But could you help us to understand the reason? All of our devs encountered that issue this morning without changing anything in the configuration.
TIA

Today, google released version 12.0.0 for library "com.google.firebase".
You can see in ../node_modules/react-native-fcm/android/build.gradle:

dependencies {
    ...
    compile 'com.google.firebase:firebase-core:+'
    compile 'com.google.firebase:firebase-messaging:+'
}

react-native-fcm will use last version of "com.google.firebase:firebase-core " and "com.google.firebase:firebase-messaging"
It's not compatible with the current version of "react-native-fcm" so I lowered the version and it worked

Hi guys, I've made a perm fix for this @ #859!

You can easily fix this (by defining your own google services version) by adding googlePlayServicesVersion=<your_version> in your gradle.properties, assuming you have my pull request.

Do let me know if there are any issues!

@sy92th thanks!

@sy92th Thanks a lot!

@sy92th Thanks. save my day

it works but after that my Android App crashes on starting https://github.com/evollu/react-native-fcm/issues/861

I am getting `Error:Execution failed for task ':react-native-camera:processReleaseResources'.

Error: more than one library with package name 'com.google.android.gms.license'` error while building Android app.

Please let me know solution to fix this.

@kkarmalkar you will have to make the same changes for the gradle file in react-native-camera.

@yangtaufoo Can you please paste exact (sample) lines to add in gradle file

I added this code in the end of android/build.gradle and I still have same error
```allprojects {
repositories {
configurations.all {
resolutionStrategy {
force 'com.google.firebase:firebase-messaging:11.4.0'
force 'com.google.firebase:firebase-core:11.4.0'
force 'com.google.android.gms:play-services-gcm:11.4.0'
}
}
}
}

did i miss anything?

Error:

Execution failed for task ':react-native-google-analytics-bridge:processReleaseResources'.

Error: more than one library with package name 'com.google.android.gms.license'
```

@petro-shkuratenyuk you need to paste a snippet of your error. However, i would assume that some other libraries do have google play dependencies too. They also need to fix their gradle files.

Just check where you are using the library and don't use the latest version. Check it out:

dependencies {

// DON'T
//    compile 'com.google.android.gms:play-services-auth:+'
// YES
    compile 'com.google.android.gms:play-services-auth:9.2.1' 
}

At least until it is fixed, I'll use like this.

I think my problem comes from Onesignal. Anyone else who is using onesignal?

the fix is analogous to any packages that have the issue. just make sure you do not have any google related dependencies defined with “+”

@yangtaufoo I'm still a bit confused.
Is auto upgrading to v12 causing the issue?

@evollu You have to add the ext object with the property(s) you wish to override in your android/build.gradle (Reference: https://developer.android.com/studio/build/gradle-tips.html#configure-project-wide-properties)

@yangtaufoo I mean what is the root cause of
Error: more than one library with package name 'com.google.android.gms.license'

@evollu Google updated their Google API for Android (https://developers.google.com/android/guides/releases) and it caused multiple libraries to fail, still trying to find what’s the root cause. Will get back once I’ve got an answer but using an old version is the best fix for now as the wildcard “+” will choose the latest at 12.0.0.

Edit: I have a gut feeling it’s related to this. (https://stackoverflow.com/questions/48365687/gradle-exclude-group-from-compile). Might want to look into it by using it in the test example

Still happening to me even if I have added forcing version to 11.4.0.
Error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-fcm:processReleaseResources'.
> Error: more than one library with package name 'com.google.android.gms.license'

@reetou When I added force it didn't work. Try to find which linked lib is causing this and change the '+' for a specific version like 9.2.1 or something else.

Got the culprit it's with react-native-device-info (Now Confirmed) it has this in it's build.gradle:

def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION    = "+"

 `  defaultConfig {
     minSdkVersion 16
     targetSdkVersion project.hasProperty('targetSdkVersion') ? project.targetSdkVersion : 
 DEFAULT_TARGET_SDK_VERSION
    versionCode 2
    versionName "1.1"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
}
lintOptions {
   warning 'InvalidPackage'
  }
 }
dependencies {
 def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ?   
 project.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
 compile 'com.facebook.react:react-native:+'
 compile "com.google.android.gms:play-services-gcm:$googlePlayServicesVersion"
 }`

@leaphawk this is my issue to...so is this than PR time for react-native-device-info? or can we override in our project gradle?

@sy92th
Do you know how to downgrade the firebase version in ionic framework?

@evollu This is my write up about the problem. The compilation problem is due to the upgrade of multiple sdk & tools. Refer to https://github.com/facebook/react-native/issues/18479#issuecomment-375200874

Edit 2
@evollu you'd need to upgrade the android files to use the new Firebase framework. I'm able to compile & run my project on 12.0.0 however, there's a crash on the library similar to #621

My approach is scan all android project and update version of google play services directly to each module build.gradle
Detail here: https://medium.com/p/2fd245027832
Hope it can help you.

@mcconkiee You can override it see this

Non of above works for me :(

After all this resolve issue

allprojects {
    repositories {
        ...
        configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                def requested = details.requested
                if (requested.group == 'com.google.android.gms') {
                    details.useVersion '11.8.0'
                }
                if (requested.group == 'com.google.firebase') {
                    details.useVersion '11.8.0'
                }
            }
        }
  }
}

android/build.grandle

work Perfect for me Thanks a lo.

sorted out... thanks

@yangtaufoo can you point me some document regarding what I need to do for playservice v12?

if all above doesn' t work try this
Try to find all your packages with gms included in your node modules.
Do this to your android/build.gradle

allprojects {
    repositories {

        // Temp fix for com.google.android.gms.license
        configurations.all {
            resolutionStrategy {

                // Put your gms packages here with 11.8.0 attached
                force "com.google.android.gms:play-services-analytics:11.8.0"
                force "com.google.android.gms:play-services-auth:11.8.0"
                force "com.google.android.gms:play-services-gcm:11.8.0"
                force "com.google.android.gms:play-services-location:11.8.0"
            }
        }

        mavenLocal()
        jcenter()

        maven { url "https://maven.google.com" }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

platform/android/build.gradle

Hi I have one question about editing the files.
Can we directly edit the build.gradle file or do we need any other tools to do it?
Thank you !

Hi, You can edit it, directly and Sync your Project, I mean in Android
Studio of course.

Regards.

On Thu, Mar 22, 2018 at 9:25 PM, huoguoislife notifications@github.com
wrote:

Hi I have one question about editing the files.
Can we directly edit the build.gradle file or do we need any other tools
to do it?
Thank you !


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/evollu/react-native-fcm/issues/857#issuecomment-375509675,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Aa17l-UAIc7l87pWx1Qvszqci7H1iY7Xks5thE8cgaJpZM4Sy4gS
.

Thank you !! I will try it now :))

Regards, I hope this to help you.
El mar 22, 2018 9:28 PM, "huoguoislife" notifications@github.com escribió:

Thank you !! I will try it now :))


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/evollu/react-native-fcm/issues/857#issuecomment-375510109,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Aa17l-A361de9fWLU2JcCTLr-HuMWlRLks5thE_ZgaJpZM4Sy4gS
.

This works for me in android/build.gradle:

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven { url "https://jitpack.io" }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {                                  // <-- Add this
            url 'https://maven.google.com/' 
            name 'Google'
        }
        configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                def requested = details.requested
                def googlePlayServicesVersion = '11.8.0'
                if (requested.group == 'com.google.android.gms') {
                    details.useVersion googlePlayServicesVersion
                }
                if (requested.group == 'com.google.firebase') {
                    details.useVersion googlePlayServicesVersion
                }
            }
        }
    }
}

@evollu It will take some time as I'm not very familiar with the Google API framework and your library

This is my medium post on how to upgrade to solve the issue.

https://medium.com/@chuckyong_3313/react-native-android-build-compilation-issue-with-google-play-api-for-android-v12-0-0-ccb2f1a0fb9c

@tobob thank you boss, its working like charm!

I was working on Ionic pro package and still can not solve this problem after trying all the solutions above. Somehow using the command $cordova build android it succeed and generate the apk file I need. Not sure where or what the problem is.
Thank you all anyway!!

however I now don't use my resolution, I did update package to latest version and it works well

@sy92th It worked for me too. I just had to add
force 'com.google.firebase:firebase-analytics:11.8.0'

to discover that I just printed the gradle dependency graph
./gradlew app:dependencies --configuration compile

and looked the 12.0.0 occurences

but if i want to use the 12.0.0 version?

As we know fire functions is avaiable since 12.

is there a way to solve that without downgrading?

Updating gradle to 4.1 seems to solve all conflicts..

@cubissimo Indeed, I ubgraded to gradle 4.6, and using Google Play Services 12.0.0 built just fine. Thanks!

All,

Whilst forcing the versions to be lower than v12 works (as above) this isn't a long term solution and you'll eventually be unable to use some libraries that do keep up to date with GMS versions such as ourselves (react-native-firebase).

The recommended approach would be to update your android project to use the latest gradle wrapper and android build tools, here's some instructions taken from our React Native Firebase v4 change log to help you do this:

## Upgrading gradle and Android build tools

Due to some breaking changes in v12 of the Android libs, you'll need to upgrade your Gradle version to at least v4.4 and make a few other tweaks as follows:

1) In android/gradle/wrapper/gradle-wrapper.properties, update the gradle URL to gradle-4.4-all.zip
2) In android/build.gradle check that you have google() specified in the buildScript repositories section:

buildscript {
    repositories {
        jcenter()
        google()  // <-- Check this line exists
        ...
    }

3) In android/build.gradle update Android build tools to version 3.1.0:

classpath 'com.android.tools.build:gradle:3.1.0'

4) In android/app/build.gradle update all your compile statements to be implementation, e.g.

implementation(project(':react-native-firebase')) {
    transitive = false
}

5) In android/app/build.gradle, update all the firebase and gms dependencies to 12.0.1


Patching outdated RN modules

In an ideal world RN modules are all kept up to date on gradle dependencies and such; but in the real world most might never upgrade their GMS versions/gradle build files, this isn't the end of the line though. You can successfully patch any of the modules you want to change the versions / dependency definitions of (e.g. to use the new gradle api/implementation/compileOnly syntax) using the patch-package npm module.

It's pretty straight-forward:

  1. Change/correct the modules you have issues with inside your node_modules dir and get them all building successfully together
  2. Once your android project builds and runs smoothly then run patch-package modulename-1 modulename-2 etc in the root of your project and it will create a patches directory in your project (contains all the changes you made in node_modules for each of the packages you specified in the command)
  3. Commit this new directory as part of your git repo
  4. Add patch-package as a post-install script on your package.json and it will auto patch after every npm/yarn install
  5. Profit 🎉

Links for reference:
https://github.com/invertase/react-native-firebase/blob/master/android/build.gradle#L83
https://github.com/invertase/react-native-firebase/blob/master/tests/android/app/build.gradle#L75

@tobob thanks, this worked for me, additionaly I changed this in my package.json "PLAY_SERVICES_VERSION": "11.8.0",

Everything is fine but when i install app on my device, it crash after install

screenshot_2018-10-08-12-04-53-508_com miui bugreport_20181008_120541885

below is my manifest file

package="com.mysalesplus">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:allowBackup="false"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize"
    android:launchMode="singleTop"
    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

  <receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher"/>
  <receiver android:enabled="true" android:exported="true"  android:name="com.evollu.react.fcm.FIRSystemBootEventReceiver">
     <intent-filter>
          <action android:name="android.intent.action.BOOT_COMPLETED"/>
          <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
          <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
          <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
  </receiver>










</application>

below is my gradle configuration

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.mysalesplus"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
dependencies {
compile project(':react-native-device-info')
compile project(':react-native-vector-icons')
compile project(':react-native-fcm')
compile project(':react-native-touch-id')
compile project(':react-native-keychain')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.facebook.react:react-native:+'
compile 'com.google.firebase:firebase-core:12.0.1'
compile 'com.google.firebase:firebase-messaging:12.0.1'
compile 'com.google.android.gms:play-services-gcm:12.0.1'

// From node_modules

}
apply plugin: "com.google.gms.google-services"

Was this page helpful?
0 / 5 - 0 ratings