我是android新手。我正在构建一个需要Map和FCM的应用程序。因此,要使用gms自定义标记并设置纬度和度数。
这是我的应用级gradle构建文件。
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
}
apply plugin: 'com.google.gms.google-services'
以下是我的项目级gradle构建文件。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
因此,当我在app level gradle文件中包含以下依赖项时。
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
我在运行应用程序时遇到以下错误。
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/internal/zzab;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command 'C:\Program
Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 20.671 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
但是当我删除firebase-messaging依赖关系时,它正在工作。请帮忙。提前致谢
答案 0 :(得分:0)
在您的gradle中使用相同版本的Gms
和firebase
依赖项。
由于您只使用Google地图,因此无需导入整个库,只使用地图选择部分。
com.google.firebase:firebase-messaging:10.2.1
com.google.android.gms:play-services-maps:10.2.1
你的代码中的:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
com.google.firebase:firebase-messaging:10.2.1
com.google.android.gms:play-services-maps:10.2.1
}