简体   繁体   中英

Error in the build. gradle ( Multiple dex files define )

I'm getting this error:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

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;

when running the app!

But I guess the problem is in the gradle. I searched for the solution, I found that there may be different versions of play service declarations. But I didn't find any errors there!

Please help me to resolve the problem. I am new to Firebase and dependencies.

This is my build gradle (app):

// 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
}

This is the build.gradle(project) file:

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'

This is because when you using:

// Single target that includes all FirebaseUI libraries above
compile 'com.firebaseui:firebase-ui:2.3.0'

is the same as using:

// 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'

which is in the documentation , it says that it needs Firebase/Play Service Version 11.0.4. But you instead using 11.2.2, so the firebase-ui library will include its transitive dependencies, which is using 11.0.4. Hence the clash happened.

So you can use the Firebase/Play Service Version 11.0.4 or you can add play service Auth.

For the Auth, you need to include the play service version:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM