Android 在一个本地项目中使用GoogleMap和FCM
我想在一个react原生项目中使用google map和FCM,首先我在项目中添加了FCM,一切正常,但当我添加google map时,我遇到了一个错误: 我在谷歌上搜索了很多,有很多答案我都试过了,但没有一个对我有用,例如: ,有人帮我。我会提供我的项目的一些屏幕截图,如果你需要其他东西,让我知道。 注意:我使用的是最新版本的Android 在一个本地项目中使用GoogleMap和FCM,android,react-native,gradle,npm,build.gradle,Android,React Native,Gradle,Npm,Build.gradle,我想在一个react原生项目中使用google map和FCM,首先我在项目中添加了FCM,一切正常,但当我添加google map时,我遇到了一个错误: 我在谷歌上搜索了很多,有很多答案我都试过了,但没有一个对我有用,例如: ,有人帮我。我会提供我的项目的一些屏幕截图,如果你需要其他东西,让我知道。 注意:我使用的是最新版本的react native(v0.56.0) 我在一起使用这些库时遇到了很多问题,最后我得到了这个配置,通过使用下面的配置,我可以成功地构建和运行我的项目: andr
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+"
}
...
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'
#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
android/app/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+"
}
...
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'
#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
android/gradle/wrapper/gradle wrapper.properties
文件:
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+"
}
...
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'
#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
并且对于安装
react native maps
非常有用。这很可能是由于fcm和map引入的Google Play服务版本存在冲突。您应该尝试使用项目范围的渐变配置
您还可以阅读一个信号的配置(它与firebase具有相同的功能)以了解一点您的问题,或者更好地使用android studio打开您的项目,您将看到确切的问题
compile('com.onesignal:onesignal:3.9.1'){
//排除com.android.support(android支持库),因为版本范围从26.0.0开始
//这是因为CompileSDK版本默认为23,不能低于支持库版本
//而且,默认根项目缺少从26.0.0中删除所需的GoogleMaven回购协议+
排除组:“com.android.support”
//保留com.google.android.gms(google Play services library),因为该版本范围从10.2.1开始
}
您的问题是react-native map和firebae依赖项彼此不同,因此您需要使用与项目中使用的react-native maps和firebase或任何其他API相同的版本感谢您的回答,但当我使用最新版本的react-native时,我会遇到这个问题。你能解释一下如何解决这个问题吗?你使用CRNA吗?如果CRNA指的是create react native app,是的,我使用了下面的命令来创建我的项目,有什么问题吗?没有,没有什么问题,但因为我没有使用CRNA,我是以本机方式启动我的应用,所以我没有面对你面临的问题。您是否使用react native
版本尝试了我的配置?请注意,您应该使用正确版本的gradle。您好,您可以点击此链接。事实上,我只是想在我的项目中排除所有google play服务。