4

I am trying to add react-native-maps into my react-native-firebase starter app. I did not get the error until I tried adding react-native-maps. Below is the code after I followed their instructions exactly. I tried changing the maps dependency to 15.0.1 and removing the duplicate play services, but that didn't fix anything. Any help or insight is much appreciated! I've been futzing with this and searching for answers for over a week now.

dependencies {
    implementation project(':react-native-vector-icons')
    // react-native-google-signin
    implementation(project(':react-native-google-signin')) {
        exclude group: "com.google.android.gms"
    }
    implementation 'com.google.android.gms:play-services-auth:15.0.0'

    // react-native-fbsdk
    implementation project(':react-native-fbsdk')

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

    // RNFirebase required dependencies
    implementation "com.google.firebase:firebase-core:15.0.2"
    implementation "com.google.android.gms:play-services-base:15.0.0"

    // RNFirebase optional dependencies
    implementation "com.google.firebase:firebase-auth:15.1.0"
    implementation "com.google.firebase:firebase-database:15.0.0"
    implementation "com.google.firebase:firebase-firestore:16.0.0"

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

    // react-native-maps required dependencies
    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:10.0.1'
    implementation 'com.google.android.gms:play-services-maps:10.0.1'
}

// 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'
Brian Kopp
  • 429
  • 4
  • 6

2 Answers2

2

Updating after testing and finding the proper solution..

Ok so I'm only using Firebase for cloud messaging right now so my solution is probably much simpler than yours will be. Basically I started by adding in firebase-core and it complained about play-services-measurement-base being requested multiple times at different versions. So I excluded that from the firebase-core dependency AND added it independently forcing the version that it was requested at. It then complained about firebase-analytics which I followed the same pattern as above, however, then it gave me the first error again for play-services-measurement-base. I had to exclude that from the firebase-analytics to proceed.

Next I added in the firebase-messaging and it gave me the same error for the firebase-iid dependency, to which I followed the previous pattern.

You have a lot more firebase dependencies so you'll probably have to go through one by one like this.

Here's my dependencies block.

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"
    implementation project(':react-native-device-info')
    implementation project(':react-native-config')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-sentry')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-maps')
    implementation project(':react-native-firebase')
    implementation "com.google.android.gms:play-services-base:${rootProject.ext.googlePlayServicesVersion}"
    implementation ("com.google.android.gms:play-services-measurement-base:15.0.4") {
        force = true
    }
    implementation ("com.google.firebase:firebase-analytics:16.0.0") {
        force = true
        exclude module: 'play-services-measurement-base'
        exclude module: 'firebase-analytics-impl'
    }
    implementation ("com.google.firebase:firebase-analytics-impl:16.0.0") {
        force = true
        exclude module: 'play-services-measurement-base'
    }
    implementation ("com.google.firebase:firebase-iid:16.0.0") {
        force = true
    }

    implementation ('com.google.firebase:firebase-core:16.0.0'){
        exclude module: 'play-services-measurement-base'
        exclude module: "firebase-analytics"
        exclude module: "firebase-analytics-impl"
    }
    implementation ('com.google.firebase:firebase-messaging:17.0.0'){
        exclude module: 'firebase-iid'
    }
}

I also setup project wide properties for react-native-maps to used as mentioned in their Android documention here https://github.com/react-community/react-native-maps/blob/master/docs/installation.md#android

Oh I should also mention that in my project level gradle build file, my buildscript dependencies needed updating.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

Hope this helps! Good luck

basudz
  • 997
  • 1
  • 6
  • 14
  • I should also mention that this only seems to happen with firebase-core:16.0.0 and firebase-messaging:17.0.0. When I used the versions specified in their docs 15.0.2 for both packages (rather than the latest versions), I didn't have any errors and didn't need to do any of this exclusion and forcing wizardry. – basudz Jun 14 '18 at 02:30
1

I finally figured it out, and I feel really stupid that it took so long to figure out. All I had to do was change the play-services-base and play-services-map versions to 15.0.1. I also had to clean the build after changing it.

Thanks for looking into it basudz, your solution was wayyyy over my head. I'm not as familiar with Android as I should be. I'm trying to get more familiar with it, it's a bitch.

Sukhbir
  • 1,410
  • 14
  • 33
Brian Kopp
  • 429
  • 4
  • 6
  • Also, if you're following the react-native-maps guide, make sure not to just copy/paste everything blindly. There are bits you might have to omit, otherwise you'll be calling things twice and it'll throw errors. – Brian Kopp Jul 30 '18 at 05:15