SciJoker SciJoker - 1 year ago 235
Android Question

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

After I have updated my Studio from 0.3.7 to 0.4.0, i can't compile my project.
I found solution on stackoverflow: Duplicate files copied (Android Studio 0.4.0)

I update my project to gradle 0.7.+
But i don't know, where i'm must put 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


Answer Source

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 ''
    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/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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download