Android Studio 0.4 Duplicate files copied in APK META-INF/LICENSE.txt

AndroidGradleAndroid Gradle-Plugin

Android Problem Overview


After I have updated my Studio from 0.3.7 to 0.4.0, I can't compile my project. I found a solution on stackoverflow: https://stackoverflow.com/questions/20673888/duplicate-files-copied-android-studio-0-4-0

I updated my project to gradle 0.7.+, but I don't know where I must put the next strings:

android {

    packagingOptions {
       exclude 'META-INF/LICENSE.txt'
    }
}

My logcat: log

Execution failed for task ':Prog:packageDebug'.
> Duplicate files copied in APK META-INF/LICENSE.txt
  	File 1: /home/scijoker/AndroidStudioProjects/ProgProject/Prog/libs/httpclient-4.1.1.jar
  	File 2: /home/scijoker/AndroidStudioProjects/ProgProject/Prog/libs/httpclient-4.1.1.jar

P.S. Develop in ubuntu 13.04

Android Solutions


Solution 1 - Android

Putting the dependecies at the top and the packageOptions at the end worked for me.

apply plugin: 'android'. 

Here is my full build.gradle at the app folder.

dependencies {
    compile 'com.android.support:support-v4:+'
    compile files('libs/apache-mime4j-0.6.jar')
    compile files('libs/httpmime-4.0.jar')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 10
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-    rules.txt'
    }


    packagingOptions {
        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'
    }
}

EDIT: Almost all OS licence include the obligation to "include a copy of the licence" into your project. So this means, that you have to include a copy of all OS licences you use into you projects. By "excluding" them in gradle, you violate the licences.

Excluding them from the project might not be the best option. Thank you R.S. for the info.

Solution 2 - Android

Attention!! Possible OpenSource license violation.

With excluding license.txt files as proposed above you may violate some opensource licenses as it is a common point in opensource licences to agree to add it to your source. Better check your opensource licences.

Update: Until there is a better solution, use

packagingOptions {
   pickFirst  'META-INF/license.txt'
}

like this you at least fulfill a part of the license obligation

You also can try:

packagingOptions {
   merge 'META-INF/license.txt'
}

Solution 3 - Android

just add

android {
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }
}

in build.gradle

Solution 4 - Android

You can fix it by adding the following code to project/app/build.gradle:

android {
    // Fixed build error : Duplicate files copied in APK META-INF/xxx
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
    }
}

Solution 5 - Android

I was facing the same problem as per new version of gradle, Below build.gradle text format work for me :

There are two jackson jars in my libs folder.

android {
         compileSdkVersion 21
         buildToolsVersion "21.1.2"

         defaultConfig {
            applicationId "com.omtlab.myapplication"
            minSdkVersion 14
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
         }
         buildTypes {
             release {
                 minifyEnabled false
                 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
         }
         packagingOptions {
            exclude 'libs/jackson-core-asl-1.9.13.jar'
            exclude 'libs/jackson-mapper-asl-1.9.13.jar'
            exclude 'META-INF/ASL2.0'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/NOTICE'
         }
}

dependencies {
    //compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/jackson-core-asl-1.9.13.jar')
    compile files('libs/jackson-mapper-asl-1.9.13.jar')
}

Solution 6 - Android

Adding:

packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
}

worked for me, biniam_Ethiopia's solution is probably the most fail-safe

Solution 7 - Android

While inserting this code

android{

packagingOptions{
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
 }
}

MAKE SURE if in error it is showing

>> Duplicate files copied in APK META-INF/LICENSE.txt

then add

 android{

packagingOptions{
    exclude 'META-INF/LICENSE.txt'
 }

}

if in error it is showing

>> Duplicate files copied in APK META-INF/LICENSE

then add

 android{

packagingOptions{
    exclude 'META-INF/LICENSE'
 }

}

if in error it is showing

>> Duplicate files copied in APK META-INF/license.txt

then add

 android{

packagingOptions{
    exclude 'META-INF/license.txt'
 }

}

In short text CASE and document FORMAT(.txt) is so important.

(this error exist in Android Studio 1.1.0 also)

Solution 8 - Android

This will help you solve the problem

packagingOptions {
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/DEPENDENCIES'
}

Solution 9 - Android

packagingOptions {
    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'
}

Add in build.gradle file and syn project

Solution 10 - Android

I just add 2:

android{

packagingOptions{
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/LICENSE'
 }

}

Solution 11 - Android

This may very well be bad practice, however if you are including multiple large libraries, you may find yourself working through hundreds of these kinds of conflicts.

Listed below is a super-simple fix for such cases:

android { 
    ....
    packagingOptions {
        // Allow the compilation process to choose the dependencies for us.
        pickFirst "**"
    }
}

Solution 12 - Android

I had a similar error and solved it without the packingOptions() and exclude function. I was adding two dependencies but one was a sub-group of the first. This caused the error, once I removed one of them I got a clean build. I recommend checking for a similar error within your dependency block.

Solution 13 - Android

When using java-jwt and jackson-core together use following:

exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-annotations/pom.properties")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-annotations/pom.xml")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.xml")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-databind/pom.properties")
exclude("META-INF/maven/com.fasterxml.jackson.core/jackson-databind/pom.xml")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiona.black13View Question on Stackoverflow
Solution 1 - AndroidbiniamView Answer on Stackoverflow
Solution 2 - AndroidR.AView Answer on Stackoverflow
Solution 3 - AndroidshankeyView Answer on Stackoverflow
Solution 4 - AndroidAlfredZhongView Answer on Stackoverflow
Solution 5 - AndroidDhiral PandyaView Answer on Stackoverflow
Solution 6 - AndroidJan WilmansView Answer on Stackoverflow
Solution 7 - AndroidShreekant NView Answer on Stackoverflow
Solution 8 - AndroidSuresh SarakView Answer on Stackoverflow
Solution 9 - AndroidGajendra kumarView Answer on Stackoverflow
Solution 10 - AndroidjosedlujanView Answer on Stackoverflow
Solution 11 - AndroidMapsyView Answer on Stackoverflow
Solution 12 - AndroidAndroid AmatureView Answer on Stackoverflow
Solution 13 - AndroidOlcay ErtaşView Answer on Stackoverflow