19

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.

HendraWD
  • 2,984
  • 2
  • 31
  • 45
Ram Rote
  • 199
  • 1
  • 1
  • 9
  • 2
    Possible duplicate of [Android Studio 0.4 Duplicate files copied in APK META-INF/LICENSE.txt](http://stackoverflow.com/questions/20827885/android-studio-0-4-duplicate-files-copied-in-apk-meta-inf-license-txt) – e4c5 Jun 15 '16 at 00:18

3 Answers3

58

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.

Mohammad Arman
  • 7,020
  • 2
  • 36
  • 50
4

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'
}
Ismail
  • 725
  • 8
  • 23
dsharew
  • 10,377
  • 6
  • 49
  • 75
1

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

Only add this block.

packagingOptions {
    exclude '**/*.txt'
}
nurisezgin
  • 1,530
  • 12
  • 19