2

I have a android studio project contains two modules use same library (jsoup). When i compie app it will show

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/org.jsoup/jsoup/pom.xml File1: C:\Users\G.gradle\caches\modules-2\files-2.1\org.jsoup\jsoup\1.8.2\64238922c4006c3d0a9951c4c03983ecc6a1e1a0\jsoup-1.8.2.jar File2: C:\Users\G\AndroidStudioProjects\twrb\app\build\intermediates\exploded-aar\twrb\webviewtimetablesearcher\unspecified\jars\classes.jar

The dependencies in build.gradle of two modules as show below.

dependencies {
    compile 'org.jsoup:jsoup:1.8.2'
}

And this is build.gradle of app.

dependencies {
    compile project(':moduleA')
    compile project(':moduleB')
}

How to fix it?? Thanks.


This is my whole build.gradle of app

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.test.tmp"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/maven/org.jsoup/jsoup/pom.xml'
        exclude 'org/jsoup/nodes/entities-base.properties'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.2.4'
    }
}

// Required because retrolambda is on maven central
repositories {
    mavenCentral()
}

apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'

dependencies {
    compile 'com.android.support:support-v4:23.2.1'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'io.realm:realm-android:0.87.5'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'io.reactivex:rxjava:1.1.0'
    compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'junit:junit:4.12'
    compile project(':moduleA')
    compile project(':moduelB')
}
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
aiueoH
  • 728
  • 1
  • 8
  • 24

1 Answers1

3

For resolve it you must add

android {
    packagingOptions {
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }
}

in build.gradle

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
  • check http://stackoverflow.com/questions/33951853/com-android-build-api-transform-transformexception-com-android-builder-packagin – Amit Vaghela May 17 '16 at 08:25
  • Thanks for your reply. But the duplicate file is META-INF/maven/org.jsoup/jsoup/pom.xml. I've tried "exclude" but is shows another duplicate file : org/jsoup/nodes/entities-base.properties. If i exclude it will not work. So i search others solution to solve this problem. – aiueoH May 17 '16 at 08:35
  • post your build.gradle of app. – Amit Vaghela May 17 '16 at 08:37
  • write above code of my answer in your build.gradle of **moduleA and moduleB** – Amit Vaghela May 17 '16 at 08:48