Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Duplicate lib file copied in APK-META-INF/license.txt " error in Android Studio

I am using below 2 lib's in project 1. spring-core-3.1.0.RELEASE.jar 2. spring-web-3.1.0.RELEASE.jar

But android studio is considering duplicate entry for above lib's and giving error while packaging.


Error:duplicate files during packaging of APK E:\Code\iDoc\app\build\outputs\apk\app-debug-unaligned.apk
    Path in archive: META-INF/license.txt
    Origin 1: E:\Code\iDoc\app\libs\spring-core-3.1.0.RELEASE.jar
    Origin 2: E:\Code\iDoc\app\libs\spring-web-3.1.0.RELEASE.jar
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'META-INF/license.txt'
      }
    }
------------------------------------------------------------

Anybody faced similar problem ?

Please suggest some-work around for this error.

like image 568
Ram Rote Avatar asked Aug 10 '15 05:08

Ram Rote


3 Answers

Go to your build.gradle file and add the following line:

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

In my case I had to add like this one:

apply plugin: 'com.android.library'    
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.15'
    compile 'com.google.code.gson:gson:2.2.4'
    compile "org.apache.httpcomponents:httpcore:4.4.1"
    compile "org.apache.httpcomponents:httpmime:4.3.6"


}

Note:

  1. Meta-files doesn't affect any programmatic functions of application. Meta files basically contains Textual information like legal-notice, Licences etc of open sources libraries. Excluding it will not affect any thing.

  2. When we use multiple 3rd party open source libraries, sometimes 2 or more projects has same named text files (Example: License.txt or Notice.txt or dependencies.txt). That causes the conflict during build time. In that moment our mighty android studio suggest us to exclude those conflicting meta files.

like image 144
Mohammad Arman Avatar answered Nov 12 '22 21:11

Mohammad Arman


Important: When excluding the files note that it is case sensitive

I added this to my gradle and it was not working:

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

I was gettting error:

Duplicate files copied in APK META-INF/notice.txt

So the fix is to add META-INF/notice.txt :

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
}
like image 35
dsharew Avatar answered Nov 12 '22 20:11

dsharew


I have most simple solution for txt files. If you remove all txt files in the dependency.

Only add this block.

packagingOptions {
    exclude '**/*.txt'
}
like image 1
nurisezgin Avatar answered Nov 12 '22 19:11

nurisezgin