我需要帮助,我是Android Studio中的新手,并且收到此错误消息:

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/database/DatabaseUtilsCompat.class

这是我的build.gradle文件,希望对您有所帮助:
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.app_name.vallic.hr"
        minSdkVersion 14
        targetSdkVersion 25
        multiDexEnabled true

        ndk {
            moduleName "player_shared"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }


    }

    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
        all*.exclude group: 'com.android.support', module: 'support-annotations'
    }

    sourceSets.main {
        jni.srcDirs = []// <-- disable automatic ndk-build call
    }
}

dependencies {
    compile('com.google.android.gms:play-services:+') {
        exclude module: 'support-v4'
        compile files('libs/dagger-1.2.2.jar')
        compile files('libs/javax.inject-1.jar')
        compile files('libs/nineoldandroids-2.4.0.jar')
        compile files('libs/support-v4-19.0.1.jar')
        compile('com.android.support:multidex:1.0.1')
    }
}

最佳答案

multidex也具有support v4库类,您已经单独包含了v4库。

因此,您必须从support v4库中排除multidex模块。

像这样更改您的mulitdex库初始化。

    compile ('com.android.support:multidex:1.0.1'){
            exclude module: 'support-v4'
        }

您的依赖项初始化应该是这样的。
dependencies {
    compile('com.google.android.gms:play-services:+') {
        exclude module: 'support-v4'
    }
    compile files('libs/dagger-1.2.2.jar')
    compile files('libs/javax.inject-1.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/support-v4-19.0.1.jar')
    compile('com.android.support:multidex:1.0.1'){
    exclude module: 'support-v4'
    }
}

希望能帮助到你:)

10-04 12:44
查看更多