我正在尝试将 Firebase Firestore 数据库添加到我的 Android 应用程序,但出现此错误:
任务“:app:transformDexArchiveWithExternalLibsDexMergerForDebug”执行失败。
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
这是我的build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "nfciue.nfcsmartanimalpassport"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
flatDir {
dirs 'libs'
}
maven {
credentials {
username "sdkuser"
password "taplinx"
}
url "http://maven.taplinx.nxp.com/nexus/content/repositories/taplinx/"
}
}
}
dependencies {
//noinspection GradleCompatible
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.firebase:firebase-firestore:11.8.0'
compile('taplinx-android:nxpnfcandroidlib:1.3@aar') {
transitive = true
}
apply plugin: 'com.google.gms.google-services'
还“编译'com.google.firebase:firebase-firestore:11.8.0'”导致警告说: 所有 gms/firebase 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 11.8.0、10.0.1。示例包括 com.google.android.gms:play-services-basement:11.8.0 和 com.google.android.gms:play-services-analytics:10.0.1 less... (Ctrl +F1) 有一些库或工具和库的组合不兼容,或者可能导致错误。一种这样的不兼容性是使用不是最新版本的 Android 支持库版本(或者特别是低于您的 targetSdkVersion 的版本)进行编译。
作为初学者,这些错误和警告对我来说很复杂。有什么帮助吗?
最佳答案
将此添加到您的应用级构建 gradle:
implementation 'com.google.android.gms:play-services-analytics:11.8.0'
这将始终清除“所有 gms/firebase 库必须使用完全相同的版本规范”。
至于 dex 问题,我以前遇到过很多次,并且总是通过使用最新版本的 compileSdkVersion 和我使用的库来解决。
关于java - Firebase Firestore 库导致 : java. lang.RuntimeException : com. android.builder.dexing.DexArchiveMergerException:无法合并 dex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49545425/