Home » Android » gradle – Android Studio 0.4 Duplicate files copied in APK META-INF/LICENSE.txt

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

Posted by: admin March 11, 2020 Leave a comment

Questions:

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: 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

How to&Answers:

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.

Answer:

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

Answer:

just add

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

in build.gradle

Answer:

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

Answer:

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')
}

Answer:

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

Answer:

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)

Answer:

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

Answer:

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

Answer:

I just add 2:

android{

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

}

Answer:

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.

Answer:

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")

Answer:

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 "**"
    }
}