我在应用程序中使用jar合并得到了与类相关的错误

时间:2017-12-13 15:34:09

标签: java android

我收到类似

的错误
  

“错误:任务执行失败   ':应用程序:transformClassesWithJarMergingForDebug'。 >   com.android.build.api.transform.TransformException:   java.util.zip.ZipException:重复条目:   组织/阿帕奇/公地/ IO / CopyUtils.class“

这是我的build.gradle

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.user.emoapp"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true

}
dexOptions {
    javaMaxHeapSize "4g"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
useLibrary 'org.apache.http.legacy'
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'])


compile 'com.android.support:design:23.4.0'

compile 'com.google.code.gson:gson:2.8.0'
compile 'com.microsoft.projectoxford:face:1.0.0'
compile 'org.apache.commons:commons-io:1.3.2'

}

请建议我一个解决方案。我很蠢。

1 个答案:

答案 0 :(得分:0)

尝试将此添加到您的gradle

 configurations.all {
        resolutionStrategy.dependencySubstitution {
            substitute module('org.apache.commons:commons-io:1.3.2') with module('commons-io:commons-io:1.3.2')
        }
    }

完全gradle应该看起来像这样

    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.user.emoapp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    dexOptions {
        javaMaxHeapSize "4g"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    useLibrary 'org.apache.http.legacy'
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
     configurations.all {
        resolutionStrategy.dependencySubstitution {
            substitute module('org.apache.commons:commons-io:1.3.2') with module('commons-io:commons-io:1.3.2')
        }
    }

}

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


    compile 'com.android.support:design:23.4.0'

    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.microsoft.projectoxford:face:1.0.0'
    compile 'org.apache.commons:commons-io:1.3.2'

    }