【问题标题】:Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. Fix this issue错误:任务“:app:transformClassesWithMultidexlistForDebug”执行失败。修复此问题
【发布时间】:2018-03-22 12:41:14
【问题描述】:

帮我解决这个问题,因为我是 android 的初学者,我需要一些帮助..

错误:任务 ':app:transformClassesWithMultidexlistForDebug' 执行失败。

java.io.IOException: Can't write [D:\bi.mobile\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\sort.jar] Vijay.gradle\caches\modules-2\files-2.1\com.google.code.gson\gson\2.8.0\c4ba5371a29ac9b2ad6129b1d39ea38750043eff\gson-2.8.0.jar(;;;;;;**.class)] (重复的 zip 条目 [gson-2.8.0.jar:com/google/gson/annotations/Expose.class]))

这是我的“build.gradle”文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26


    defaultConfig {
        applicationId "com.bimobile"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    // ..
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    //noinspection GradleCompatible,GradleCompatible
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'

    compile files('libs/android-async-http-1.4.4.jar')
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.google.android.gms:play-services-maps:11.8.0'
    compile files('libs/gson-2.8.0.jar')
    compile 'org.lucasr.twowayview:twowayview:0.1.4'
    compile "com.daimajia.swipelayout:library:1.2.0@aar"
}
android { sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/anim'] } } }

【问题讨论】:

标签: java android build.gradle gson


【解决方案1】:

这是因为您的项目中有多个 GSON 依赖项。你只需要使用一个。你应该只通过 maven 使用这个库:

compile 'com.google.code.gson:gson:2.8.0'

您应该删除以下内容:

compile files('libs/gson-2.8.0.jar')

不要忘记删除libs/ 文件夹中的gson-2.8.0.jar 文件。因为您使用以下行包含库中的所有 jar:

compile fileTree(dir: 'libs', include: ['*.jar'])

【讨论】:

    【解决方案2】:

    在你的gradle 添加这一行 compile 'com.android.support:multidex:1.0.0'

    在你的应用单例类上添加这个extends MultiDexApplication

    这应该可以解决您的问题。

    【讨论】:

    • @Hemant Parmar 感谢您的回复......但是这个解决方案对我不起作用......我再次遇到同样的错误......
    • 好的,你能试着删除这行compile files('libs/gson-2.8.0.jar')吗?你已经有了compile 'com.google.code.gson:gson:2.8.0',所以不需要我之前提到的那一行
    猜你喜欢
    • 2018-08-01
    • 2016-01-23
    • 2018-06-09
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多