Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase dependency updates are required to fix gradle v4+ builds #1155

Closed
xzilja opened this issue May 29, 2018 · 36 comments
Closed

Firebase dependency updates are required to fix gradle v4+ builds #1155

xzilja opened this issue May 29, 2018 · 36 comments
Labels
Impact: Build Error Behaviour causing build failure Platform: Android

Comments

@xzilja
Copy link
Contributor

xzilja commented May 29, 2018

Issue

Google recently released gradle versions 3.3.0 and 3.3.1 that had bug in them related to multiple build types (like dev conflicting with prod etc...) they afterwards released gradle v4.0.0 and v4.0.1 with fixes, but these presented their own errors for outdated dependencies

In my case error was

The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.4,15.0.4]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

None of my dependencies are using it, after inspecting my dependency tree via

$ ./gradlew app:dependencies

I found out that this particular module is coming from firebase-auth

+--- com.google.firebase:firebase-auth:15.1.0
|    +--- com.google.android.gms:play-services-base:[15.0.1,16.0.0) -> 15.0.1 (*)
|    +--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 15.0.1 (*)
|    +--- com.google.android.gms:play-services-flags:[15.0.1,16.0.0) -> 15.0.1
|    |    +--- com.google.android.gms:play-services-base:[15.0.1] -> 15.0.1 (*)
|    |    \--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
|    +--- com.google.android.gms:play-services-tasks:[15.0.1,16.0.0) -> 15.0.1 (*)
|    +--- com.google.firebase:firebase-analytics:[15.0.1,16.0.0) -> 15.0.2
|    |    +--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 15.0.1 (*)
|    |    +--- com.google.android.gms:play-services-measurement-base:[15.0.2] -> 15.0.2

I created a stack-overflow issue and basically only suggestion was to make sure that firebase modules are up to date.

Looking at last 2 updates from firebase: https://firebase.google.com/support/release-notes/android#20180523 I updated ones I have inside my projects app/build.gradle to all the latest ones, but error persisted, I believe because these are not upgraded in react-native-firebase ? Fix was to use gradle 3.2.1 for now.

A side question: do we need to specify these firebase packages in react-native-firebase, i.e. will they not be inherited from parent project?

Environment

  1. Application Target Platform: Android
  1. Development Operating System: macOS High Sierra, Gradle v4
  1. Build Tools: Android Studio 3
  1. React Native version: 0.55.4
  1. RNFirebase Version: 4.2.0
  1. Firebase Module: Auth (I think many others)
@xzilja xzilja changed the title Firebase dependency updates are required to fix gradle 3.3+ builds Firebase dependency updates are required to fix gradle v4+ builds May 29, 2018
@openGeeksLab
Copy link

+1

@chrisbianca
Copy link
Contributor

@iljadaderko @MariaSyed @openGeeksLab I've just pushed up support for this on a build-issues branch. There are a few other things that need looking at on the iOS side before this can be merged and released, but if you'd like to give it a try, you can do the following:

npm install --save https://github.com/invertase/react-native-firebase#build-issues

You'll need to update a few things:

  1. android/build.gradle:

i) classpath 'com.google.gms:google-services:4.0.1'
ii) Make sure google() appears above jcenter() in both buildscripts and allprojects

  1. android/app/build.gradle:

Update Android libs to the latest specified here: https://firebase.google.com/support/release-notes/android#20180523

Note that firebase-ads:16.0.0 does not actually exist, you'll need to stick on 15.0.1.

@chrisbianca chrisbianca added Platform: Android Impact: Build Error Behaviour causing build failure labels May 29, 2018
@vmahishi
Copy link

vmahishi commented Jun 2, 2018

I had the same issue, the culprit is Firebase-Core as well in addition to Auth as pointed out by @iljadaderko

smallex pushed a commit to smallex/CRWB-Research-Group that referenced this issue Jun 4, 2018
@DeepaSriramRR
Copy link

Hi, I am facing the same issue. Is there any update on this ? I am working on the build-issues branch which fixed the issue in android and want to know when it will be pushed to release. I would also like to know about the iOS status.

@aMarCruz
Copy link
Contributor

aMarCruz commented Jun 9, 2018

@DeepaSriramRR , as a temporal workaround you can disable version check of the Google plugin.

At the end of your android/app/build.gradle:

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

@chrisbianca
Copy link
Contributor

This has now been merged and will be part of our next release.

@juanxme
Copy link

juanxme commented Jun 21, 2018

remove com.google.gms.google-services plugin

@ms502040
Copy link

ms502040 commented Jun 25, 2018

this is working - last libs form google
(earlier than the pullrequest to merge google have new libraries)

dependencies {
  // compile fileTree(include: ['*.jar'], dir: 'libs')
  api "com.facebook.react:react-native:+"  // From node_modules
  api "com.android.support:support-v4:$supportVersion"
  compileOnly('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') {
    transitive = true
  }
 // compileOnly "com.google.android.gms:play-services-base:15.0.1"
  compileOnly "com.google.firebase:firebase-ads:15.0.1"
  compileOnly "com.google.firebase:firebase-auth:16.0.2"
  compileOnly "com.google.firebase:firebase-config:16.0.0"
  compileOnly "com.google.firebase:firebase-core:16.0.1"
  compileOnly "com.google.firebase:firebase-crash:16.0.1"
  compileOnly "com.google.firebase:firebase-database:16.0.1"
  compileOnly "com.google.firebase:firebase-firestore:17.0.2"
  compileOnly "com.google.firebase:firebase-functions:16.0.1"
  compileOnly "com.google.firebase:firebase-invites:16.0.1"
  compileOnly "com.google.firebase:firebase-storage:16.0.1"
  compileOnly "com.google.firebase:firebase-messaging:17.0.0"
  compileOnly "com.google.firebase:firebase-perf:16.0.0"
  compileOnly 'me.leolin:ShortcutBadger:1.1.21@aar'
}

@hegelstad
Copy link

@chrisbianca can you confirm if it is a part of 4.3.0?

@Salakar
Copy link
Member

Salakar commented Jul 7, 2018

@hegelstad yes it will be part of v4.3.0


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

@hegelstad
Copy link

hegelstad commented Jul 7, 2018

@Salakar I'm severely struggling with this issue. Using yarn add https://github.com/invertase/react-native-firebase#build-issues doesn't seem to work.

Do you have a minimal example of which versions that works together?

These are my deps:

dependencies {
    implementation (project(':react-native-firebase')) {
      transitive = false
    }
    implementation "com.google.firebase:firebase-core:16.0.1"
    implementation "com.google.firebase:firebase-auth:16.0.2"
    implementation "com.google.firebase:firebase-firestore:17.0.2"
    implementation "com.google.firebase:firebase-messaging:17.1.0"

    implementation (project(':react-native-maps')) {
      exclude group: 'com.google.android.gms', module: 'play-services-base'
      exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }

    implementation "com.google.android.gms:play-services-base:15.0.1"
    implementation "com.google.android.gms:play-services-maps:15.0.1"

    implementation project(':react-native-wheel-datepicker')
    implementation project(':react-native-vector-icons')

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.1.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
}
buildscript {
    repositories {
        maven {
          url 'https://maven.google.com'
          name 'Google'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'com.android.tools.build:gradle:3.1.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

EDIT: My issues disappear when I remove react-native-maps from the dependencies. I'll investigate further.
EDIT2: It builds when edit node_modules/react-native-maps/lib/android/build.gradle:

def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION    = "12.0.4"

to:

def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION    = "15.0.1"

However i get a new error: RNFirebaseFirestore.documentGet got 5 arguments, expected 5.

Any ideas? I am running this version of RNFirebase: yarn add https://github.com/invertase/react-native-firebase#build-issues

EDIT3: Fixed it by bumping react-native-firebase's messaging dep to 17.1.0.
compileOnly "com.google.firebase:firebase-messaging:17.1.0"

@yeomann
Copy link

yeomann commented Aug 6, 2018

ok, I had something similar scenario, my current react native firebase is: "react-native-firebase": "^4.3.8", basically my all configs are somewhat similar to @hegelstad but I was still getting this error,

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dependencies'.
> The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[10.2.4,10.2.4], [15.0.1,15.0.1]], but resolves to 15.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

The error basically address that some other module is also relaying on Google play service, and it might have a default version which is conflicting with the one react-native-firebase is using. This is same situation explained above by @hegelstad that react-native-maps were having a default version which was causing the issue.
Obviously idle solution won't be relying on going on each module and modifying there build.gradle
so, the simple solution is actually this

ext {
    buildToolsVersion = "27.0.3"
    minSdkVersion = 19
    compileSdkVersion = 27
    targetSdkVersion = 27
    supportLibVersion = "27.1.1"
    googlePlayServicesVersion = "15.0.1" // <-- this line here tell other modules to overwrite and use this instead of default
}

add above ext{} in build.gradle. If you are installing latest react-native with 0.56.0 then you will be having already ext{} with targeting SDK of 26. If the issue by change still persists, then add following at the end of same build.gralde

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion '27.0.3'
                supportLibVersion = "27.1.1"
                googlePlayServicesVersion = "15.0.1" //<-- life save line? 
            }
        }
    }
}

@mowbell
Copy link

mowbell commented Aug 15, 2018

I suggest you first check it:
#1155 (comment)
And verify in your graddle.properties, to remove it:
org.gradle.configureondemand=true
Taken of:
https://proandroiddev.com/bundling-react-native-during-android-release-builds-ec52c24e200d
It works for me

@vikrantnegi
Copy link

@yeomann @mowbell This does resolve the sync issue but this forces google maps to use google play services version of 15.0.1 which is causing the app to crash on startup. Google maps uses google play services version of 10.0.1 and works normally.

I'm getting an error in Logcat:

08-16 10:27:28.997 30875-30902/? E/AndroidRuntime: FATAL EXCEPTION: Thread-4
    Process: com.arttiee_reactnative, PID: 30875
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/maps/GoogleMapOptions;
        at com.airbnb.android.react.maps.AirMapManager.<init>(AirMapManager.java:55)
        at com.airbnb.android.react.maps.MapsPackage.createViewManagers(MapsPackage.java:39)
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:756)
        at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:173)
        at com.facebook.react.CoreModulesPackage.access$200(CoreModulesPackage.java:53)
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:130)
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:127)
        at com.facebook.react.LazyReactPackage.createNativeModules(LazyReactPackage.java:79)
        at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:109)
        at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1175)
        at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1145)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1086)
        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916)
        at java.lang.Thread.run(Thread.java:760)
     Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.GoogleMapOptions
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.airbnb.android.react.maps.AirMapManager.<init>(AirMapManager.java:55) 
        at com.airbnb.android.react.maps.MapsPackage.createViewManagers(MapsPackage.java:39) 
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:756) 
        at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:173) 
        at com.facebook.react.CoreModulesPackage.access$200(CoreModulesPackage.java:53) 
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:130) 
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:127) 
        at com.facebook.react.LazyReactPackage.createNativeModules(LazyReactPackage.java:79) 
        at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:109) 
        at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1175) 
        at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1145) 
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1086) 
        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116) 
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916) 
        at java.lang.Thread.run(Thread.java:760) 
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/safeparcel/zza;
        at com.airbnb.android.react.maps.AirMapManager.<init>(AirMapManager.java:55) 
        at com.airbnb.android.react.maps.MapsPackage.createViewManagers(MapsPackage.java:39) 
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:756) 
        at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:173) 
        at com.facebook.react.CoreModulesPackage.access$200(CoreModulesPackage.java:53) 
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:130) 
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:127) 
        at com.facebook.react.LazyReactPackage.createNativeModules(LazyReactPackage.java:79) 
        at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:109) 
        at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1175) 
        at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1145) 
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1086) 
        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116) 
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916) 
        at java.lang.Thread.run(Thread.java:760) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.safeparcel.zza" on path: DexPathList[[zip file "/data/app/com.arttiee_reactnative-1/base.apk"],nativeLibraryDirectories=[/data/app/com.arttiee_reactnative-1/lib/arm, /data/app/com.arttiee_reactnative-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.airbnb.android.react.maps.AirMapManager.<init>(AirMapManager.java:55) 
        at com.airbnb.android.react.maps.MapsPackage.createViewManagers(MapsPackage.java:39) 
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:756) 
        at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:173) 
        at com.facebook.react.CoreModulesPackage.access$200(CoreModulesPackage.java:53) 
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:130) 
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:127) 
        at com.facebook.react.LazyReactPackage.createNativeModules(LazyReactPackage.java:79) 
        at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:109) 
        at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1175) 
        at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1145) 
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1086) 
        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116) 
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916) 
        at java.lang.Thread.run(Thread.java:760) 
08-16 10:27:29.007 30875-30875/? W/unknown:ReactNative: Packager connection already open, nooping.

@yeomann
Copy link

yeomann commented Aug 16, 2018

sorry but you might have something else. I am having no issue here @vikrantnegi also its not necessary that react native maps will just depends upon version 10. if you read the source of react native maps, you can see ternary statement saying use default if app doesn't specify google play service version

@linux08
Copy link

linux08 commented Sep 10, 2018

Issue persist when integrating along with react-native google maps ,@vikrantnegi found a fix yet

@Victorams
Copy link

Having the same problem described by @vikrantnegi . App freezes on startup when the sync issue is solved by setting GooglePlayVersion to 15.0.1. I use google maps due to some other library on my project.

@vikrantnegi
Copy link

@linux08 @Victorams Yes the issue get fixed by setting googlePlayServicesVersion = "15.0.1".

@tonmanayo
Copy link

same problem

buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}

 }
 dependencies {
     classpath 'com.android.tools.build:gradle:3.1.4'
     classpath 'com.google.gms:google-services:4.1.0'
     classpath 'io.fabric.tools:gradle:1.25.4'
     classpath 'com.google.firebase:firebase-plugins:1.1.1'
     // NOTE: Do not place your application dependencies here; they belong
     // in the individual module build.gradle files
 }

}

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

ext {
buildToolsVersion = "26.0.2"
minSdkVersion = 18
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "26.1.0"
}


apply plugin: "com.android.application"
apply plugin: "com.google.firebase.firebase-perf"
apply plugin: 'io.fabric'

import com.android.build.OutputFile

/**

  • The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
  • and bundleReleaseJsAndAssets).
  • These basically call react-native bundle with the correct arguments during the Android build
  • cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
  • bundle directly from the development server. Below you can see all the possible configurations
  • and their defaults. If you decide to add a configuration block, make sure to add it before the
  • apply from: "../../node_modules/react-native/react.gradle" line.
  • project.ext.react = [
  • // the name of the generated asset file containing your JS bundle
  • bundleAssetName: "index.android.bundle",
  • // the entry file for bundle generation
  • entryFile: "index.android.js",
  • // whether to bundle JS and assets in debug mode
  • bundleInDebug: false,
  • // whether to bundle JS and assets in release mode
  • bundleInRelease: true,
  • // whether to bundle JS and assets in another build variant (if configured).
  • // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
  • // The configuration property can be in the following formats
  • // 'bundleIn${productFlavor}${buildType}'
  • // 'bundleIn${buildType}'
  • // bundleInFreeDebug: true,
  • // bundleInPaidRelease: true,
  • // bundleInBeta: true,
  • // whether to disable dev mode in custom build variants (by default only disabled in release)
  • // for example: to disable dev mode in the staging build type (if configured)
  • devDisabledInStaging: true,
  • // The configuration property can be in the following formats
  • // 'devDisabledIn${productFlavor}${buildType}'
  • // 'devDisabledIn${buildType}'
  • // the root of your project, i.e. where "package.json" lives
  • root: "../../",
  • // where to put the JS bundle asset in debug mode
  • jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
  • // where to put the JS bundle asset in release mode
  • jsBundleDirRelease: "$buildDir/intermediates/assets/release",
  • // where to put drawable resources / React Native assets, e.g. the ones you use via
  • // require('./image.png')), in debug mode
  • resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
  • // where to put drawable resources / React Native assets, e.g. the ones you use via
  • // require('./image.png')), in release mode
  • resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
  • // by default the gradle tasks are skipped if none of the JS files or assets change; this means
  • // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
  • // date; if you have any other folders that you want to ignore for performance reasons (gradle
  • // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
  • // for example, you might want to remove it from here.
  • inputExcludes: ["android/", "ios/"],
  • // override which node gets called and with what additional arguments
  • nodeExecutableAndArgs: ["node"],
  • // supply additional arguments to the packager
  • extraPackagerArgs: []
  • ]
    */

project.ext.react = [
entryFile: "index.js",
bundleInRelease : false,
resourcesDirRelease : "src/release/res"
]

apply from: "../../node_modules/react-native/react.gradle"

/**

  • Set this to true to create two separate APKs instead of one:
    • An APK that only works on ARM devices
    • An APK that only works on x86 devices
  • The advantage is the size of the APK is reduced by about 4MB.
  • Upload all the APKs to the Play Store and people will download
  • the correct one based on the CPU architecture of their device.
    */
    def enableSeparateBuildPerCPUArchitecture = false

/**

  • Run Proguard to shrink the Java bytecode in release builds.
    */
    def enableProguardInReleaseBuilds = true

android {

lintOptions {
    disable 'GradleCompatible'
    disable 'InvalidPackage'
}

dexOptions {
    javaMaxHeapSize "4g"
}

compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
    applicationId "xxx"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 3
    versionName "1.0.2"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
    multiDexEnabled true
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86"
    }
}
signingConfigs {
    release {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}
buildTypes {
    release {
        debuggable false
        shrinkResources enableProguardInReleaseBuilds
        zipAlignEnabled enableProguardInReleaseBuilds
        minifyEnabled enableProguardInReleaseBuilds
        useProguard enableProguardInReleaseBuilds
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        signingConfig signingConfigs.release
    }
    debug {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
        def versionCodes = ["armeabi-v7a":1, "x86":2]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }
    }
}

}

dependencies {
implementation project(':react-native-splash-screen')

implementation project(':react-native-device-info')
implementation project(':react-native-vector-icons')
implementation project(':react-native-svg')
implementation project(':react-native-image-crop-picker')
implementation project(':react-native-i18n')
implementation project(':react-native-contacts')
implementation project(':react-native-config')
implementation project(':react-native-camera')
implementation project(':react-native-awesome-card-io')
implementation project(':react-native-push-notification')
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
// implementation 'com.android.support:multidex:1.0.3'

implementation(project(':react-native-firebase')) {
    transitive = false
}
implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.android.gms:play-services-base:15.0.1"

implementation 'com.google.firebase:firebase-messaging:17.3.2'
implementation('com.crashlytics.sdk.android:crashlytics:+') {
    transitive = true
}

implementation "com.android.support:appcompat-v7:27.1.1"
implementation 'com.android.support:support-annotations:27.1.1'
implementation "com.facebook.react:react-native:0.20.1"
implementation fileTree(dir: "libs", include: ["*.jar"])

}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

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

Error:

The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[16.0.2,16.0.2]], but resolves to 16.0.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

@luispeerez
Copy link

worked for me after adding the following code to android/build.gradle

maven { url 'https://maven.google.com' name 'Google' }

@Braden1996
Copy link

Can't get this working either :(
If I add com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true, the build succeeds but can't connect to my firebase project 🤔

@arivanandan
Copy link

arivanandan commented Sep 25, 2018

In app/build.gradle, I used

    implementation "com.google.firebase:firebase-core:16.0.3"
    implementation "com.google.firebase:firebase-messaging:17.3.0"
    implementation "com.google.android.gms:play-services-base:15.0.1"
    implementation "com.google.android.gms:play-services-location:15.0.1"

ATM, I believe the tutorials specify 16.0.1 for firebase-core and 17.1.0 for firebase-messaging.

Go to https://firebase.google.com/docs/android/setup and scroll to the bottom and match the Available Libraries section.

(This apart from the googlePlayServicesVersion mentioned above.)

@mcorner
Copy link
Contributor

mcorner commented Sep 28, 2018

I know this issue is closed, but I wanted to leave my own strategy for solving this problem so that perhaps it helps someone or someone can tell me a simpler way. If google is listening, you have little idea of the pain this has caused....

We use a large number of libraries that depend on google services and firebase. We don't control those libraries, and some are not well maintained. We could fork them all, but that is it's own form of terrible. The only way we could get everything to work together is three things:

  1. Exclude the google and firebase modules from being included by modules in your app gradle. For instance a few:
    implementation(project(':react-native-fcm')) {
      exclude group: "com.google.firebase"
    }
    implementation(project(':tipsi-stripe')) {
        exclude group: "com.google.android.gms"
    } 
    implementation(project(':react-native-google-sign-in')) {
        exclude group: "com.google.android.gms"
    }
  1. Reinclude the ones you need, for instance:
    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.google.firebase:firebase-messaging:17.3.2'
    implementation 'com.google.android.gms:play-services-auth:16.+'
    implementation 'com.google.android.gms:play-services-wallet:16.+'
    implementation 'com.google.firebase:firebase-auth:16.+'

  1. Fix all the "is being requested by various other libraries" resolution problems with a custom resolver in your top level gradle file. For instance:
allprojects {
  repositories {

  configurations.all {
    resolutionStrategy {
      force 'com.google.android.gms:play-services-basement:15.0.1'
      force 'com.google.android.gms:play-services-tasks:15.0.1'
      force 'com.google.android.gms:play-services-base:15.0.1'
      force 'com.google.firebase:firebase-analytics:16.0.3'
      force 'com.google.firebase:firebase-iid:17.0.2'
      force 'com.google.android.gms:play-services-ads-lite:15.0.1'
      force 'com.google.android.gms:play-services-ads:15.0.1'
      force 'com.google.android.gms:play-services-gass:15.0.1'
      force 'com.google.android.gms:play-services-wallet:16.0.0'
      }
    }

Without 1) you get conflicts where the same library is being included twice. I think you get duplicate symbols and the like.

Without 2) your program will fail at runtime because it can't find the libraries it needs.

Without 3) it will fail to compile with messages like "The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]]..." My impression is that this error is coming from google's own gradle plugin. Gradle's dependency tree doesn't show these dependencies once you exclude them and that error comes from google?

The solution here: #1155 (comment) only works if every underlying module you are using respects that config variable, which many (most?) do not.

There must be an easier way!!!

@mpalmerlee
Copy link

@mcorner I was hitting the same The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]]... issue after adding the react-native-google-signin package, after checking back through the setup instructions it recommends adding the ext section to the build.gradle file like this:

ext {
    googlePlayServicesVersion   = "15.0.1"
}

Once I did that all the mismatched dependency errors went away.

https://github.com/react-native-community/react-native-google-signin/blob/master/android-guide.md#choose-dependency-versions-optional

@gagangoku
Copy link

@mcorner 💯
Thank you for the detailed steps. Every time I have to add firebase as a dependency in any project, i spent 3+ days just getting it to build. Google really needs to fix their shit.

It would be a huge help if you could just tell me what versions would work for me. These are the modules i need to use:
react-native-firebase
react-native-maps
react-native-share
react-native-code-push
appcenter-crashes
appcenter-analytics
appcenter
react-native-vector-icons

Questions:
com.google.firebase:firebase-messaging : what version to use ?
com.google.firebase:firebase-core : what version to use ?

in android/build.gradle:
classpath 'com.android.tools.build:gradle:' : what version to use ?
classpath 'com.google.gms:google-services:' : what version to use ?

@gagangoku
Copy link

gagangoku commented Oct 4, 2018

Following worked for me:

android/app/build.gradle
apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = true

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.homedruid.customer.app.rn.notificationtester"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    compile (project(':react-native-firebase')) {
        exclude group: 'com.google.android.gms'
        exclude group: "com.google.firebase"
        transitive = false;
    }
    compile (project(':react-native-share')) {
        exclude group: 'com.google.android.gms'
    }
    compile (project(':react-native-code-push')) {
        exclude group: 'com.google.android.gms'
    }
    compile (project(':appcenter-crashes')) {
        exclude group: 'com.google.android.gms'
    }
    compile (project(':appcenter-analytics')) {
        exclude group: 'com.google.android.gms'
    }
    compile (project(':appcenter')) {
        exclude group: 'com.google.android.gms'
    }

    compile (project(':react-native-vector-icons')) {
        exclude group: 'com.google.android.gms'
    }
    compile (project(':react-native-maps')){
        exclude group: 'com.google.android.gms'
    }
    compile ("com.google.android.gms:play-services-base:$googlePlayServicesVersion") {
        force = true;
    }
    compile ("com.google.android.gms:play-services-basement:$googlePlayServicesVersion") {
        force = true;
    }
    compile ("com.google.android.gms:play-services-maps:$googlePlayServicesVersion") {
        force = true;
    }
    compile ("com.google.firebase:firebase-iid:17.0.0") {
        force = true;
    }

    // Firebase dependencies
    implementation "com.google.firebase:firebase-core:16.0.3"
    implementation "com.google.firebase:firebase-messaging:17.3.0"

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true        // Its sad that i had to resort to this

android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"

        googlePlayServicesVersion = "15.0.1"
        androidMapsUtilsVersion = "0.5+"
    }
    repositories {
        google()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        mavenLocal()
        google()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
    }
}
subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 26
                buildToolsVersion "27.0.3"
            }
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

@mcorner
Copy link
Contributor

mcorner commented Oct 4, 2018

@mpalmerlee That is only going to work in limited cases, where all of your modules respect that variable. Some do (stripe and google-signin seem to), but we use several libraries that do not.

@gagangoku I think the key is that you used: com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true // Its sad that i had to resort to this

Which does seem dangerous, but may be doing the same thing I did in the end anyway.

I agree, Google has made this super hard.

@gagangoku
Copy link

@mcorner : agreed.

@mhmoafi
Copy link

mhmoafi commented Oct 16, 2018

I have this error with
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation "com.google.firebase:firebase-auth:16.0.3"
but new fbAuth
implementation "com.google.firebase:firebase-auth:16.0.4"
it is work fine for me

@niranjanbprajapati
Copy link

I am facing the issue i have reported at here

If some one can help it would be great stuck at this badly. its basically conflicts in react-native-maps vs react-native-firebase as if i remove maps it will work fine.

@jonatslab
Copy link

still having this issue..

@arepageek
Copy link

arepageek commented Oct 23, 2018

I was having this issue and after testing i just change on build.gradle

from:

allprojects {

  repositories {

    mavenLocal()

    jcenter()
    maven {

      // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm

      url "$rootDir/../node_modules/react-native/android"

    }
    google() 
   }
} 

to

allprojects {

  repositories {

    mavenLocal()

    maven {

      // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm

      url "$rootDir/../node_modules/react-native/android"

    }
    google()
    jcenter()
   }
}

and now its working

@AndrewHenderson
Copy link

This resolved it: https://stackoverflow.com/a/51213879/933711

Move jcenter() to the bottom of repositories in android/build.gradle.

buildscript {
    ext.kotlin_version = '1.2.50'
    repositories {
        google()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
    }

and

allprojects {
    repositories {
        google()
        jcenter()
    }
  }

@jasan-s
Copy link

jasan-s commented Jan 9, 2019

What resolved this error for me was to add the following to the bottom of android/app/build.gradle
right after apply plugin: 'com.google.gms.google-services'

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

// THE FOLLOWING CODE IS NEEDED TO GET FIREBASE ANDROID SDK WORKING
configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
    }
}
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

It would be nice to add this to the Docs

@blogui91
Copy link

@mpalmerlee thank you!!! that did the trick

@Ajaykumar02
Copy link

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

Instead of above line use,
googleServices { disableVersionCheck = true } if your google services version is >4.0 'com.google.gms:google-services:4.3.2'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impact: Build Error Behaviour causing build failure Platform: Android
Projects
None yet
Development

No branches or pull requests