我想在一个 React Native 项目中使用 google map 和 FCM,首先我在项目中添加了 FCM,一切正常,但是当我添加 google map 时,我遇到了一个错误:
我在谷歌上搜索了很多,有很多我尝试过的答案,但没有一个对我有用,例如: https://github.com/firebase/FirebaseUI-Android/issues/1230 , 谁来帮帮我。我将提供我的项目的一些屏幕截图,如果您需要其他东西,请告诉我。
最佳答案
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/