Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve Duplicate files copied in APK META-INF/rxjava.properties

I am using rxjava and rxvolley on my android aplication. When I try to run it I get this error

Execution failed for task ':testapp:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
            File1: C:\Users\Daniel\.gradle\caches\modules-2\files-2.1\io.reactivex\rxjava\1.1.0\748f0546d5c3c27f1aef07270ffea0c45f0c42a4\rxjava-1.1.0.jar
            File2: C:\Users\Daniel\.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava\2.0.3\d2f725668bd22e21170381b23f8fbdf72c69d886\rxjava-2.0.3.jar

I have a exclude.gradle file like this

android {
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/rxjava.properties'
    exclude 'META-INF/rxjava.PROPERTIES'
    exclude 'META-INF/RXJAVA.properties'
    exclude 'META-INF/RXJAVA.PROPERTIES'
    exclude 'META-INF/rxjava'
    exclude 'META-INF/RXJAVA'
}

lintOptions {
    abortOnError false
}
}

How can I fix this problem?

like image 407
Dani Garcia Avatar asked Feb 01 '17 01:02

Dani Garcia


3 Answers

I had the same problem. The way I fixed it is adding the packagingOptions in app gradle as described in Duplicated file rxjava.properties

android {

    defaultConfig {
    }
    buildTypes {
    }
    packagingOptions{
        exclude 'META-INF/rxjava.properties'
    }
}
like image 149
Julián Martínez Avatar answered Nov 15 '22 18:11

Julián Martínez


I had the same issue.
In my case I am using Retrofit2 but I assume that the issue is with the rx libraries

This is the build.gradle (module:app) I am using and in my case works.

compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'

compile 'io.reactivex:rxandroid:1.1.0' //<-use this
compile 'io.reactivex:rxjava:1.1.3'    //<-use this

compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'

Anyway there is one better solution as you can see on the top

like image 41
JoCuTo Avatar answered Nov 15 '22 19:11

JoCuTo


I also have the same problem but easily removed duplicated "comment" all Rxjava related dependencies that it doesn't use in my code.

//RxJava removes or comment duplicated and not used dependencies.
      //  implementation 'com.squareup.retrofit2:adapter-rxjava:2.4.0'
       // implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
       // implementation 'io.reactivex.rxjava2:rxjava:2.1.13'
like image 33
mahmoud Zahran Avatar answered Nov 15 '22 20:11

mahmoud Zahran