Android Duplicate File Exception - android

I have downloaded the Jackson2 libraries to include in an android class. I get this error upon building:
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: \app\libs\jackson-core-2.9.1.jar File2: \app\libs\jackson-databind-2.9.1.jar File3: \app\libs\jackson-annotations-2.9.1.jar
I searched the internet and found this to be the most common answer:
packagingOptions {
exclude "META-INF/license.txt"
}
However, this doesn't fix the issue above.

You need to exclude the exact file name. From the error log, you can see that the duplicated file is META-INF/LICENSE (be aware of the case-sensitive) :
Duplicate files copied in APK META-INF/LICENSE
So, exclude it:
packagingOptions {
exclude 'META-INF/LICENSE'
}

Related

Duplicate files copied in APK META-INF/LICENSE

Error:Execution failed for task ':openpayandroid:transformResourcesWithMergeJavaResForRelease'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: /Users/ederpadilla/Downloads/driveappuble-drive-android-484430cd00e7/openpayandroid/libs/jackson-core-2.8.2.jar
File2: /Users/ederpadilla/Downloads/driveappuble-drive-android-484430cd00e7/openpayandroid/libs/jackson-core-asl-1.9.11.jar
Add this code in your app gradle file
android {
...
packagingOptions {
exclude 'META-INF/LICENSE'
}
}

DuplicateFileException: Duplicate files copied in APK project.properties [duplicate]

I'm getting below mentioned error when I'm trying to run my application.
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForAmazonCheezCoverage'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.squareup/otto/pom.xml
File1: /Users/afourtest/.gradle/caches/modules-2/files-2.1/com.crashlytics.android/crashlytics/1.1.13/e821eafa1bf489a26bdb71f95078c26785b37a1/crashlytics-1.1.13.jar
File2: /Users/afourtest/.gradle/caches/modules-2/files-2.1/com.squareup/otto/1.3.7/69d90fd7fb70e54746e26c10454c220e40a775ce/otto-1.3.7.jar
My app build.gradle is here
Add to build.gradle:
android {
...
packagingOptions {
exclude 'META-INF/maven/com.squareup/otto/pom.xml'
}
Also, instead of exclude you could use pickFirst

Gradle sync Error in Android Studio 2.2.2

I am working on a project for a client. The project seems to work fine in the old Android Studio, but ever since I updated my studio to 2.2.2, I am getting the sync error when trying to run the app, the error message is as posted below.
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: /home/empressum/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient-android/4.3.5.1/eecbb0b998e77629862a13d957d552b3be58fc4e/httpclient-android-4.3.5.1.jar
File2: /home/empressum/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3/5b0002c5fb66867ca919be0fbd86de1cfaf76da7/httpmime-4.3.jar
You might also want to check if you have 2 references of the same library or .jar included and remove the duplicate reference.
Guess you are using dependency which is conflicting with androids supplied jars. Add
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
in your gradle.
Add following into respective build.gradle file
android {
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
}
}
You are using two many libraries files for http call instead use jar file on libs or add some dependency in gradle.
The error went when I downloaded the project zip file again and run it. But this time when Android Studio asked me to update the gradle file, I denied. I dont know if this explains the error, but now the project is running fine on any device I connect.

DuplicateFileException m4b + play services 9.0

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResFor'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK jsr305_annotations/Jsr305_annotations.gwt.xml
File1:\app\build\intermediates\exploded-aar\google-maps-sdk-m4b\jars\classes.jar
File2:\app\build\intermediates\exploded-aar\com.google.android.gms\play-services-basement\9.0.0\jars\classes.jar
Add below text in build.gradle inside the android{} section to solve the problem.
android {
...
packagingOptions {
exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
exclude 'build-data.properties'
}
...
}
If getting more error DuplicateFileException add file with exclude.
Like :
Error
Duplicate files copied in APK jsr305_annotations/Jsr305_annotations.gwt.xml
Solution
exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
Adding this to your gradle file will solve your problem:
packagingOptions {
exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
}

Duplicate files copied in APK META-INF/maven/com.squareup/otto/pom.xml

I'm getting below mentioned error when I'm trying to run my application.
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForAmazonCheezCoverage'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.squareup/otto/pom.xml
File1: /Users/afourtest/.gradle/caches/modules-2/files-2.1/com.crashlytics.android/crashlytics/1.1.13/e821eafa1bf489a26bdb71f95078c26785b37a1/crashlytics-1.1.13.jar
File2: /Users/afourtest/.gradle/caches/modules-2/files-2.1/com.squareup/otto/1.3.7/69d90fd7fb70e54746e26c10454c220e40a775ce/otto-1.3.7.jar
My app build.gradle is here
Add to build.gradle:
android {
...
packagingOptions {
exclude 'META-INF/maven/com.squareup/otto/pom.xml'
}
Also, instead of exclude you could use pickFirst

Categories

Resources