【问题标题】:Error in the build. gradle ( Multiple dex files define )构建中的错误。 gradle(多个dex文件定义)
【发布时间】:2017-09-08 17:26:36
【问题描述】:

我收到此错误:

错误:任务执行失败 ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException:com.android.dex.DexException: 多个dex文件定义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'

【问题讨论】:

    标签: java android gradle android-gradle-plugin build.gradle


    【解决方案1】:

    这是因为当你使用:

    // 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 服务版本 11.0.4。但是您使用的是 11.2.2,因此 firebase-ui 库将包含其传递依赖项,即使用 11.0.4。于是就发生了冲突。

    因此您可以使用 Firebase/Play 服务版本 11.0.4,也可以添加播放服务 Auth。

    对于 Auth,您需要包含播放服务版本:

    compile "com.google.firebase:firebase-auth:11.2.2"
    compile "com.google.android.gms:play-services-auth:11.2.2"
    

    【讨论】:

    • 更改com.google.firebase 版本,而不是删除它们。
    • 我将 firebase 的版本更改为 11.0.4,它正在工作!因为我是 Firebase 和 Dependencies 的新手,所以我遇到了困难并且浪费了很多时间来解决它。有什么好的做法?
    • 对于 Firebase,不要仅仅因为它是新版本就使用最新版本。仅使用您需要的版本。对于依赖项,您需要深入挖掘库文档并尝试阅读其 build.gradle。您需要阅读有关传递依赖项和排除库依赖项的信息。这是我的 2 美分意见。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    相关资源
    最近更新 更多