DEX 错误 Android Studio - 任务 ':app:transformClassesWithMultidexlistForDebug' 执行失败

DEX error Android Studio - Execution failed for task ':app:transformClassesWithMultidexlistForDebug'

我在添加 Spinner 后遇到了这个奇怪的错误,它起作用了。我试图为它确定一些保证金。尝试构建它时出现此错误

任务“:app:transformClassesWithMultidexlistForDebug”执行失败。 重复的 zip 条目 [classes.jar:android/support/design/widget/CoordinatorLayout$Behavior.class]

所以,我尝试删除我添加的内容。没用。我尝试清理构建项目并重建,但没有成功。它试图在 Whosebug 上寻找解决方案。我遇到了,将 multiDexEnabled true 添加到我的 app.gradle,没有 success.I 也遵循了 Android link 上的文档:https://developer.android.com/studio/build/multidex.html

这也没用,所以我自己来了。我的 gradle 个文件:

app.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.meyil.androidlearning"
        minSdkVersion 15
        targetSdkVersion 26
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    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'
    implementation 'com.android.support:design:26.1.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.firebaseui:firebase-ui-database:3.2.1'
    implementation 'id.zelory:compressor:2.1.0'
    implementation 'com.squareup.okhttp:okhttp:2.5.0'
    implementation 'com.android.support:multidex:1.0.2'
}
















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

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.meyil.androidlearning">

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:icon="@mipmap/spaced_launcher_logo"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/spaced_launcher_logo_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <service android:name=".FirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".StartActivity" />
        <activity
            android:name=".RegisterActivity"
            android:parentActivityName=".StartActivity" />
        <activity
            android:name=".LoginActivity"
            android:parentActivityName=".StartActivity" />
        <activity android:name=".SettingsActivity" />
        <activity
            android:name=".StatusActivity"
            android:parentActivityName=".SettingsActivity" />
        <activity
            android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
            android:theme="@style/Base.Theme.AppCompat" />
        <activity
            android:name=".UsersActivity"
            android:parentActivityName=".MainActivity" />
        <activity android:name=".ProfileActivity">
            <intent-filter>
                <action android:name="com.example.meyil.androidlearning_TARGET_NOTIFICATION" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".ChatActivity"
            android:parentActivityName=".MainActivity"></activity>
    </application>

</manifest>

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

昨天遇到了同样的问题,所以检查了依赖关系,删除后 'android.lib.recaptcha:reCAPTCHA:+' 开始正常工作,构建没有任何错误。在我看来,您还应该尝试找到冲突的依赖项。

我通过将 compileSdk 和 targetSdk 更改为 27 以及所有其他从 26 到 27 的依赖项来修复它。:D