36

So I'm continuously receiving a gradle build error upon trying to run my project. I have searched for other solutions and some say that adding:

packagingOptions {
    exclude 'META-INF/NOTICE'
}

to my app's gradle.build would fix the issue, however, it doesn't. Here is what my app's gradle.build currently looks like.

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile 'com.google.android.gms:play-services-identity:8.3.0'
    compile 'com.firebase:firebase-client-android:2.3.1'
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.example.j.airportmeet"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    packagingOptions {
        exclude 'META-INF/NOTICE'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Edit

The full error is this:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
    File1: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.2.2\3c8f6018eaa72d43b261181e801e6f8676c16ef6\jackson-databind-2.2.2.jar
    File2: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.2.2\d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b\jackson-core-2.2.2.jar
    File3: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.2.2\285cb9c666f0f0f3dd8a1be04e1f457eb7b15113\jackson-annotations-2.2.2.jar
Sufian
  • 6,405
  • 16
  • 66
  • 120
SpecialSnowflake
  • 945
  • 4
  • 16
  • 32

3 Answers3

88

As the error message suggests you are not excluding the META-INF/LICENSE file which exists in more than one of your dependencies

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE

packagingOptions {
    exclude 'META-INF/NOTICE' // will not include NOTICE file
    exclude 'META-INF/LICENSE' // will not include LICENSE file
    // as noted by @Vishnuvathsan you may also need to include
    // variations on the file name. It depends on your dependencies.
    // Some other common variations on notice and license file names
    exclude 'META-INF/notice'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license'
    exclude 'META-INF/license.txt'
}
JBirdVegas
  • 10,855
  • 2
  • 44
  • 50
  • 4
    exclude 'META-INF/notice.txt' exclude 'META-INF/license.txt' – Vishnuvathsan Jan 21 '16 at 14:56
  • 3
    This didn't work for me, so I just removed my last dependency and it works. – humazed Apr 19 '16 at 13:25
  • 1
    This error only occurred for me after I upgraded to Android Studio 2.2.2 (from 2.1.1). 2.2.2 forced an upgrade to Gradle and then this error began occurring. Adding the excludes fixed it. Thanks. – raddevus Nov 04 '16 at 01:37
  • it doesn't work for me. but i really need the depedency of google cloud api. how do I figure this problem? – oscarz Jun 04 '17 at 22:14
4

In my case, I had two references to the same library .jar, only deleted one of them and voilà, it is compiling now, it is working.

enter image description here

2

I faced the same issue. In my case,by adding the below code to the build.gradle(Module: app), inside the android{...} tag, solved the issue

packagingOptions {
    exclude 'META-INF/NOTICE' // will not include NOTICE file
    exclude 'META-INF/LICENSE' // will not include LICENSE file
    // as noted by @Vishnuvathsan you may also need to include
    // variations on the file name. It depends on your dependencies.
    // Some other common variations on notice and license file names
    exclude 'META-INF/notice'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license'
    exclude 'META-INF/license.txt'
}
Eggcellentos
  • 1,570
  • 1
  • 18
  • 25
Md Nakibul Hassan
  • 2,716
  • 1
  • 15
  • 19