com.android.dex.DexException错误:多个dex文件定义了Lcom / google / android / libraries / places / internal / dh;

时间:2019-06-11 10:43:59

标签: android android-gradle build.gradle

我收到此错误:

Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/libraries/places/internal/dh;

我尝试清理和重建项目,但是没有成功。任何帮助将不胜感激。

Android Studio 3.0.1

项目级别build.gradle

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

allprojects {

    repositories {
        mavenCentral()
        google()
        jcenter()
        maven { url 'https://jitpack.io'
                }

    }
}

task clean(type: Delete) {

delete rootProject.buildDir

}

应用程序级别build.gradle

apply plugin: 'com.android.application'

android {

    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "in.mycrony"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 86
        versionName "2.86"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.github.barteksc:android-pdf-viewer:2.0.3'
    implementation 'com.google.android.libraries.places:places-compat:1.1.0'
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.1'
    implementation 'id.zelory:compressor:2.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.squareup.picasso:picasso:2.5.1'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
    implementation 'com.squareup.okhttp3:okhttp:3.7.0'
    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation 'com.google.firebase:firebase-database:17.0.0'
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    implementation 'com.google.android.libraries.places:places-compat:1.1.0'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.google.android.libraries.places:places:1.1.0'
    implementation project(':library')

}

apply plugin: 'com.google.gms.google-services'

库级别build.gradle

apply plugin: 'com.android.library'

apply from: "quality.gradle"

group = 'com.github.eggheadgames'

android {

    compileSdkVersion 27
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 13
        versionName "1.5.2"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        warningsAsErrors true

        disable 'OldTargetApi'
        disable 'GradleDependency'
    }
}

dependencies {


    testImplementation 'org.mockito:mockito-core:1.10.19'

    testImplementation 'org.json:json:20160212'

    implementation 'com.android.support:appcompat-v7:27.1.1'

}

我已经尝试了所有给出的答案,但无法解决此错误。

2 个答案:

答案 0 :(得分:2)

  

原因:com.android.dex.DexException:定义了多个dex文件   Lcom / google

您应该使用其中之一

 implementation 'com.google.android.libraries.places:places-compat:1.1.0'
 implementation 'com.google.android.libraries.places:places:1.1.0' //Remove

然后 Clean-Rebuild-Run

答案 1 :(得分:0)

最后,我只是将实现'com.google.android.libraries.places:places:1.0.0'用于Place Autocomplete,并对Place使用了相同的'com.google.android.gms:play-services'依赖项选择器。