在一个本机项目中使用Google Map和FCM

时间:2018-07-10 05:12:18

标签: android react-native gradle npm build.gradle

我想在一个react native项目中使用google map和FCM,首先我在项目中添加了FCM,一切都还好,但是当我添加google map时,我遇到了一个错误: enter image description here

我在Google上搜索了很多,尝试了很多答案,但是没有一个对我有用: https://github.com/firebase/FirebaseUI-Android/issues/1230 , 谁来帮帮我。我将提供我的项目的一些屏幕截图,如果您需要其他功能,请告诉我。 enter image description here

enter image description here

3 个答案:

答案 0 :(得分:3)

  

注意:我正在使用react-native(v0.56.0)的最新版本。

在一起使用这些库时遇到很多问题,最后我有了这个配置,通过使用以下配置,我可以成功构建并运行项目:

android/build.gradle文件:

buildscript {
    repositories {
        jcenter()
        google()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        classpath 'com.google.gms:google-services:3.0.0'

        // 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://maven.google.com/'
            name 'Google'
        }
    }
}

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 26
                buildToolsVersion "27.0.3"
            }
        }
    }
}

ext {
    buildToolsVersion = "27.0.3"
    minSdkVersion = 16
    compileSdkVersion = 26
    targetSdkVersion = 26
    supportLibVersion = "26.1.0"
    googlePlayServicesVersion = "11.0.2"
    androidMapsUtilsVersion = "0.5+"
}

android/app/build.gradle文件:

...
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:11.0.2'
    implementation 'com.google.android.gms:play-services-maps:11.0.2'
    implementation 'com.google.android.gms:play-services-analytics:11.0.2'
    implementation project(':react-native-fcm')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'com.amplitude:android-sdk:2.13.4'
    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'

android/gradle/wrapper/gradle-wrapper.properties文件:

#Tue Aug 01 12:26:47 IRDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

this document对于安装react-native-maps很有用。

答案 1 :(得分:0)

这很可能是由于fcm和map引入的Google Play服务版本存在冲突。您应该尝试使用整个项目范围的gradle配置。

您还可以阅读一个信号的配置(它与firebase具有相同的功能),以了解您的一些问题,或者更好的是,您可以使用android studio打开项目,您会看到确切的问题。

   compile('com.onesignal:OneSignal:3.9.1') {
        // Exclude com.android.support(Android Support library) as the version range starts at 26.0.0
        //    This is due to compileSdkVersion defaulting to 23 which cant' be lower than the support library version
        //    And the fact that the default root project is missing the Google Maven repo required to pull down 26.0.0+
        exclude group: 'com.android.support'
        // Keeping com.google.android.gms(Google Play services library) as this version range starts at 10.2.1
    }

答案 2 :(得分:0)

您的问题是react-native-map和firebae依赖关系互不相同,因此您需要使用相同版本的react-native-maps和firebase或您在项目中使用的任何其他API