Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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.

Solution 2:

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

Solution 3:

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

Only add this block.

packagingOptions {
    exclude '**/*.txt'
}

Post a Comment for ""duplicate Lib File Copied In Apk-meta-inf/license.txt " Error In Android Studio"