我收到此错误:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
block 引用>com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzeg;
运行应用程序时!
但我猜问题出在 gradle 上。我搜索了解决方案,发现可能存在不同版本的播放服务声明。但我没有发现任何错误!
请帮我解决这个问题。我是 Firebase 和依赖项的新手。
这是我的构建 gradle(应用程序):
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.google.gms:google-services:3.1.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() maven { url "https://maven.google.com" // Google's Maven repository } } } task clean(type: Delete) { delete rootProject.buildDir }
这是 build.gradle(project) 文件:
apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig { applicationId "com.eaglewap.cleancity" minSdkVersion 17 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' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) // Displaying images compile 'com.github.bumptech.glide:glide:3.6.1' //Firebase compile 'com.google.firebase:firebase-database:11.2.2' compile 'com.google.firebase:firebase-storage:11.2.2' compile 'com.google.firebase:firebase-auth:11.2.2' compile 'com.google.firebase:firebase-messaging:11.2.2' compile 'com.google.firebase:firebase-config:11.2.2' //Firebase UI // Single target that includes all FirebaseUI libraries above compile 'com.firebaseui:firebase-ui:2.3.0' compile 'com.android.support:appcompat-v7:26.0.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' } apply plugin: 'com.google.gms.google-services'
最佳答案
这是因为当您使用时:
// Single target that includes all FirebaseUI libraries above
compile 'com.firebaseui:firebase-ui:2.3.0'
与使用相同:
// FirebaseUI Database only
compile 'com.firebaseui:firebase-ui-database:2.3.0'
// FirebaseUI Auth only
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
// FirebaseUI Storage only
compile 'com.firebaseui:firebase-ui-storage:2.3.0'
位于 documentation 中,它表示需要 Firebase/Play Service 版本 11.0.4。但您改为使用 11.2.2,因此 firebase-ui 库将包含其传递依赖项,该依赖项使用 11.0.4。于是冲突就发生了。
因此,您可以使用 Firebase/Play 服务版本 11.0.4,也可以添加 Play 服务身份验证。
对于身份验证,您需要包含播放服务版本:
compile "com.google.firebase:firebase-auth:11.2.2"
compile "com.google.android.gms:play-services-auth:11.2.2"
关于java - 构建时出错。 gradle(多个dex文件定义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46121735/