Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app:transformClassesWithJarMergingForDebug'. TransformException: java.util.zip.ZipException: duplicate entry while running gradlew assembleDebug

Tags:

android

gradle

When i run : gradlew assembleDebug command on android studio project root. Building process fails nad i get this message:

What went wrong:

Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/slf4j/impl/StaticLoggerBinder.class

In my project there are two jar files: slf4j-android-1.6.1-RC1.jar and slf4j-log4j12-1.7.21.jar. And both this jars contain two jars that includes org.sl4j.impl.StaticLoggerBinder.

Here is my gradle file content which is located on app folder:

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.ias.caniasandroid"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        jumboMode true
        javaMaxHeapSize "4g"
    }
    productFlavors {
    }
}

dependencies {
    debugCompile fileTree(include: ['*.jar'], dir: 'libs')
    debugCompile files('libs/commons-lang3-3.4.jar')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
}

How can i fix the problem and run gradlew assembleDebugsuccessfully without changing contents of jar files?

like image 222
bahtiyartan Avatar asked Jan 04 '17 09:01

bahtiyartan


1 Answers

Just remove the below classes from slf4j-android-1.6.1-RC1 jar

org/sl4j/impl/StaticLoggerBinder.class
org/sl4j/impl/StaticMarkerBinder.class
org/sl4j/impl/StaticMDCBinder.class

You can exclude particular class from a jar in gradle dependency.

To do it, unzip a jar using the Copy task, exclude the desired class and then add a file dependency on the extracted classes.

task unzipJar(type: Copy) {
   from zipTree('slf4j-android-1.6.1-RC1.jar')
   into ("$buildDir/libs/slf4j") //TODO: you should update this line
   include "**/*.class"
   exclude "org/sl4j/impl/StaticLoggerBinder.class"
   exclude "org/sl4j/impl/StaticMarkerBinder.class"
   exclude "org/sl4j/impl/StaticMDCBinder.class"
}

dependencies {
   compile files("$buildDir/libs/slf4j") {
      builtBy "unzipJar"
   }
}

Note: It does everythime when your codes are compiling.

On the other hand, if you don´t want to compile the package, but if you want to compile them and exclude from your JAR you could use

jar {
    exclude('org/sl4j/impl/**')  
}
like image 174
ziLk Avatar answered Oct 29 '22 11:10

ziLk