问题
I want to use google map and FCM in one react native project , first I added FCM in project, everything was okay but when I added google map, I faced an error :
I googled a lot, there are so many answers that I have tried but none of them worked for me for example: https://github.com/firebase/FirebaseUI-Android/issues/1230 , some one help me. I will provide some screen shoots of my project , if u need something else, let me know.
回答1:
Note: I'm using the latest version of
react-native
(v0.56.0).
I have faced a lot of issues in using these libraries together and finally I've got this config, by using the configuration below I could build and run my project successfully:
android/build.gradle
file:
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
file:
...
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
file:
#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
And this document is useful for installing react-native-maps
.
回答2:
This is most likely due to conflicts in the versions of Google Play Services being pulled in by fcm and map. You should try to use project-wide gradle config.
You also can read the configuration for one signal (it have the same function with firebase) to understand a little your problem or better you can open your project with android studio, you will see exactly problem.
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
}
回答3:
your problem is that react-native-map and firebae dependencies differ from each other so u need to use the same version of react-native-maps and firebase or any other API that u are using in your project
来源:https://stackoverflow.com/questions/51257641/using-google-map-and-fcm-in-one-react-native-project