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

13

117

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

Paraguay answered 29/12, 2013 at 17:14 Comment(2)
Inside android sectionFortunna
Thanks. I put block packagingOptions() in main gradle conf file. First I inserted this block in libraries gradle files. All work's perfectly=)Paraguay
C
157

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.

Centreboard answered 9/4, 2014 at 6:0 Comment(13)
This one seems to work for me as well. What is all these exclude directives, by the way? Why do we need this?Pauperize
@Pauperize The reason we exclude the files is because we do not want the .txt (and other) files to be included in the .apk that will be generated by the build.Centreboard
exclude is not recognized outside of android{} :/Catechumen
For me it is worked with adding exclude 'META-INF/LICENSE' and exclude 'META-INF/NOTICE'.Besse
packagingOptions must be within androidEquiangular
Exclude should be inside android { }, then only it works.Ducharme
! This Solution violates all Open source licences ! As you are obliged to add the original licence text of each library to your packageAzerbaijani
@R.S I don't really understand which open source licence you are mentioning. Please give me detail so I can modify it.Centreboard
Hi. Any. 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.Azerbaijani
for most licences you need to include license.txt if you are distributing their source codes or module. When compiling the APK no source code is being distributed, executable is being distributed. So it's fine to include it in this case.Demurrage
R.S, you are aware that the convention on Android is to just have an activity in your app that displays all of the libraries you use and their respective licenses, yes? No license literally says you have to include it as a .txt file, and in fact including it in your APK would accomplish absolutely nothing.Storebought
The packagingOptions must be in the android object.Weinstein
use pickFirst instead of exclude to prevent losing the licensesPadraig
A
51

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'
}
Azerbaijani answered 16/4, 2015 at 18:20 Comment(0)
I
23

just add

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

in build.gradle

Inveigle answered 27/10, 2014 at 10:57 Comment(1)
Our are violating opensource licence like thisAzerbaijani
F
16

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'
    }
}
Fernald answered 12/7, 2015 at 11:37 Comment(3)
Hi. This problem was fixed 1.5 years ago Thanks for answerParaguay
:-) I just met this problem today and found this thread. And I don't notice the date.Fernald
You didn't notice the date AND ignored all the other answers.Rudbeckia
Q
11

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')
}
Quade answered 25/12, 2014 at 19:32 Comment(1)
Thank you! I was banging my head against this for ~5 hours today. :) It's the packagingOptions { exclude 'libs/jackson...' } that fixed it.Dendro
D
8

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

Dismuke answered 10/1, 2015 at 13:22 Comment(0)
C
8

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)

Culprit answered 19/6, 2015 at 9:49 Comment(0)
P
6

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'
}
Pulverulent answered 3/8, 2016 at 16:32 Comment(1)
why this has so many downvotes if is basically the same as the proper answer ?Redblooded
C
4
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

Corsiglia answered 23/8, 2017 at 2:13 Comment(0)
S
3

I just add 2:

android{

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

}
Sinfonia answered 13/2, 2017 at 23:18 Comment(1)
Will this be included still, in app production?Insincere
M
3

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 "**"
    }
}
Mimosa answered 23/7, 2017 at 23:30 Comment(0)
N
2

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.

Nuzzi answered 16/3, 2014 at 13:53 Comment(2)
Hi, i'm solved this problem a long time ago by adding packingOptions() . Thanks for answer) +1Paraguay
This problem is fixed in new available version of ASParaguay
H
2

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")
Hoem answered 26/11, 2015 at 9:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.