android - 在一个 react-native 项目中使用 google map 和 FCM

标签 android react-native gradle npm build.gradle

我想在一个 React Native 项目中使用 google map 和 FCM,首先我在项目中添加了 FCM,一切正常,但是当我添加 google map 时,我遇到了一个错误: enter image description here

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

enter image description here

最佳答案

Note: I'm using the latest version of 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 很有用。

关于android - 在一个 react-native 项目中使用 google map 和 FCM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51257641/

相关文章:

ios - 无法查看Firebase Analytics调试 View React Native

android - 如何强制 Jacoco 在 Gradle 中使用特定版本

jQuery手机差距: Split view using asyraf9 example not working

Android 无法让调试器离开 eclipse

android - 使用 React-Native 在 Android 模拟器上的位置请求超时

java - 在部署 AWS Lambda 时设置 bean 属性 'mongoTemplate' 时无法解析对 bean 'mongoOperations' 的引用

java - Gradle 尝试在 IntelliJ 插件项目中使用 PsiMethod 构建类失败

java - 按钮无法解析为类型 - Android 开发

android - 如何在扩展 CCLayer 的类中使用 getAssets

javascript - 如何在 React Native 中设置 axios 的休息状态