【问题标题】:com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: b.classcom.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:b.class
【发布时间】:2019-05-28 08:42:31
【问题描述】:

在我的 android 项目中使用了 gradle。我最近添加了一些 jars 文件(最后一个)。但是添加后我得到了构建错误。我的 gradle 文件是

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.myapplicationpck"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 44
        versionName "4.9"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }

    sourceSets {
        main.jni.srcDirs = []
        main.jniLibs.srcDirs = ['libs']
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/ASL2.0'
        exclude 'VERSION.txt'

    }

}

android {
    useLibrary 'org.apache.http.legacy'
}


repositories {
    mavenCentral()
    maven {
        url "https://jitpack.io"
    }
    maven {
        url 'https://maven.google.com'
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile files('libs/android-viewbadger.jar')
    compile project(':libraryMobilePaymentSDK')
    compile('com.jakewharton:butterknife:8.6.0') {
        exclude module: 'support-compat'
    }
    compile 'xml-security:xmlsec:1.3.0'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.github.aakira:expandable-layout:1.4.2@aar'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'
    compile 'com.android.support:multidex:1.0.1'
    compile 'rongi.rotate-layout:rotate-layout:2.0.0'
    compile 'com.roomorama:caldroid:3.0.1'
    compile 'com.google.guava:guava:18.0'
    compile 'org.jsoup:jsoup:1.9.1'
    compile 'com.android.support.test.espresso:espresso-core:2.2.2'
    compile 'gun0912.ted:tedpermission:1.0.3'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.intuit.sdp:sdp-android:1.0.3'
    compile 'com.github.adhishlal:gifloader:1.1'
    compile('com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.2') {
        exclude group: 'com.google.zxing'
    }
    compile 'com.github.javiersantos:BottomDialogs:1.2.1'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'

// new added jar files

    compile files('libs/simple-xml-2.7.1.jar')
    compile files('libs/mpaysdk_release_v.1.0.4.jar')
    compile files('libs/jackson-core-asl-1.9.13.jar')
    compile files('libs/jackson-mapper-asl-1.9.13.jar')
    compile files('libs/bcprov-ext-jdk15on-154.jar')
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/commons-lang-2.3.jar')
    compile files('libs/core-2.3.0.jar')
    compile files('libs/meSdk-3.6.4-SNAPSHOT7.jar')
    compile files('libs/rsadukpt.jar')


}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.jakewharton.butterknife'

现在在构建之后我得到了这样的错误:

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

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:b.class

我该如何解决这个问题。任何人都请帮助我克服这个问题。在此先感谢。

【问题讨论】:

    标签: android android-studio jar android-gradle-plugin build.gradle


    【解决方案1】:
    compile project(':libraryMobilePaymentSDK')
    compile files('libs/mpaysdk_release_v.1.0.4.jar')
    

    我认为这两个库是相同的。如果是,则尝试删除其中一个并重建您的项目。

    【讨论】:

    • 是的,你没看错,但我需要添加库和 jar 文件。它与 :libraryMobilePaymentSDK 冲突,我想从这个模块中排除这个 jar。我该怎么做?
    • 你可以像这样排除你的库 ~configurations { all*.exclude group: 'mpaysdk_release_v.1.0.4' }
    • 但是为什么在一个项目中需要两个相同的库?
    • 感谢您付出宝贵的时间来回答这个问题。我需要两个库,因为它们都有不同的功能。但不能同时设置两者。是否可以同时拥有两个库?或一些替代方法,所以请分享我会尝试..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多