Android get DuplicateFileException Error for Retrofit and Retrofit Adapter - android

after installing this libraries on project:
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
i get this error:
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/rxjava.properties
File1: /Users/mahdi/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.0.1/57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb/rxjava-2.0.1.jar
File2: /Users/mahdi/.gradle/caches/modules-2/files-2.1/io.reactivex/rxjava/1.1.5/ece7b5d0870e66d8226dab6dcf47a2b12afff061/rxjava-1.1.5.jar
I'm not sure whats problem, some documents installed them like with my solution.
packagingOptions {
exclude 'META-INF/io.reactivex.rxjava2/rxjava/2.0.1/57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb/rxjava.properties'
exclude 'META-INF/io.reactivex/rxjava/rxjava.properties'
}

problem resolved:
packagingOptions {
exclude 'META-INF/rxjava.properties'
}

Related

Gradle: Cant exclude one of two log4j dependencies?

Occuring error
While trying to build an android studio project with gradle i recieve this error:
Execution failed for task ':app:transformResourcesWithMergeJavaResForPlainDebug'.
com.android.build.api.transform.TransformException:
com.android.builder.packaging.DuplicateFileException:
Duplicate files copied in APK org/apache/log4j/lf5/config/defaultconfig.properties
File1: ...\app\libs\tn5250j.jar
File2: ...\app\build\intermediates\exploded-aar\xxx\xxx\jars\libs\log4j-1.2.17.jar
In two included .jars the library log4j is used. I must include both libs to my android application. One of them is an .aar file, the other is a .jar.
Gradle settings
Dependencies from my build.gradle:
dependencies {
debugCompile 'xxx#aar'
releaseCompile 'xxx#aar'
compile files('libs/commons-net-3.5.jar')
compile files('libs/jackson-core-2.8.1.jar')
compile files('libs/jackson-databind-2.8.1.jar')
compile files('libs/jackson-annotations-2.8.1.jar')
compile files('libs/tn5250j.jar')
}
Packaging options from my build.gradle:
packagingOptions {
exclude 'main/AndroidManifest.xml'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
}
I have no idea what tn5250j.jar is but it looks like it's an UBER jar which is packing log4j inside. You could either exclude the log4j dependency from your build (since it's packed inside tn5250j.jar) or you tweak tn5250j.jar to remove log4jand use the "tweaked" jar instead. Eg:
dependencies {
...
compile files("$buildDir/tweaked/tn5250j-tweaked.jar")
}
task tweakTn5250j(type: Zip) {
from zipTree('libs/tn5250j.jar').matching {
exclude 'org/apache/log4j/**'
}
destinationDir = "$buildDir/tweaked"
archiveName = 'tn5250j-tweaked.jar'
}
classes.dependsOn tweakTn5250j

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 Entry during Android gradle build in Task :transformClassesWithJarMergingAndroidTest

I'm getting the following exception when building my Android app with Gradle:
Execution failed for task ':transformClassesWithJarMergingForGoogleGermanDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/hamcrest/BaseDesc
The problem seems to be that in my build.gradle file I have declared:
testCompile 'org.hamcrest:hamcrest-all:1.3'
androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
However, I need both dependencies for unit tests and integration tests. How to solve this?
The problem was that another jar (Mockito) included hamcrest-core as a transitive dependency. This module contains all classes under the package name org.hamcrest.*. Hence the conflict. The solution was:
configurations {
all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
As described here: https://docs.gradle.org/current/userguide/dependency_management.html Chapter 23.4.7
Try adding the exclude parameter for repeated entries.
androidTestCompile 'org.hamcrest:hamcrest-all:1.3' {
exclude module: 'BaseDesc'
}
buildTypes {
release {
multiDexEnabled true;
}
}
try this this should work

Excluding jar file duplicate from build

First of all, I got this:
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/nostra13/universalimageloader/cache/disc/DiskCache.class
I use the UniversalImageLoader jar in my app project, but also I have a library module which also uses the exact same jar.
I tried to add something like that to my app build.gradle file:
compile (project(':imagesubsampling')){
exclude group: 'com.nostra13.universalimageloader', module: 'com.nostra13.universalimageloader'
}
or
compile (project(':imagesubsampling')){
exclude group: 'com.nostra13', module: 'universalimageloader'
}
or
compile (project(':imagesubsampling')){
exclude group: 'com.nostra13.universalimageloader'
}
Nothing works.
Therefore, my question is:
compile (project(':imagesubsampling')){
<What to write here to exclude jar file from this library>
}
Is there a better solution to get rid of duplicates?
What to write exactly?
I met this issue when there're more than one universal
image loader reference in your project(maybe in the libs folder, or in dependencies of the project,sublibs).
Check again all build.gradle files(in android studio) in your project.Keep one and delete all others would solve the problem.

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