执行任务':app:transformClassesWithJarMergingForDebug'失败

6

我创建了一个运行在API版本21及以上的Android应用程序。 但是在API级别低于21的设备上无法运行。

以下是错误日志:

错误:执行任务“:app:transformClassesWithJarMergingForDebug”时失败。 com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl.class 请帮助我解决问题。

以下是我的Gradle代码:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "*******"
        minSdkVersion 16
        targetSdkVersion 23
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
    packagingOptions {
        exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
        exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
    }
}

dependencies {
    compile fileTree(exclude: 'android-support-*.jar', dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile project(':simple-crop-image-lib')
    //    compile 'com.github.navasmdc:MaterialDesign:+'
    compile project(':material-login')
    compile 'com.android.support:multidex:1.0.1'
    compile ('com.android.support:appcompat-v7:23.4.0'){
        exclude module: 'support-v4'
    }
}
1个回答

1
首先使用以下命令编译构建:

compile 'com.android.support:multidex:1.0.1'

在您的 AndroidManifest.xml 文件中添加以下行:android:name
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="android.support.multidex.MultiDexApplication"
    >

在你的 build.gradle 文件中也添加此内容。
dexOptions {
    //incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g"
}


packagingOptions {
     exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
    exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
}

你应该将 multiDexEnabled 设置为 true。 - Arjun saini
尝试使用compileSdkVersion 24和buildToolsVersion "24.0.1",将targetSdkVersion设置为24.1.1而不是23.4.0。 - Arjun saini
查看问题并仍有问题。 - Mohit Dahiya
让我们在聊天中继续这个讨论 - Mohit Dahiya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接