1

I have a project that uses RxJava 1. Now I'm building a module component, and thinking of starting with RxJava 2.

When perform gradle sync, all good. However during compilation I got the following error

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForProductionDebug'. com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties File1: /Users/user.name/.gradle/caches/modules-2/files-2.1/io.reactivex/rxjava/1.2.5/b423532b5a3c949cbb799468f83bf566032fe98d/rxjava-1.2.5.jar File2: /Users/user.name/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.0.1/57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb/rxjava-2.0.1.jar

Is there anyway I could have them coexist in a single project (but different library), or this is a definitely no-no?

i.e. on one, I have

compile 'io.reactivex:rxjava:1.2.5'
compile 'io.reactivex:rxandroid:1.2.1'

on the other one I have

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
Elye
  • 53,639
  • 54
  • 212
  • 474

2 Answers2

1

So regarding to this documentation they can co-exist theoretically, because the classes are located in different packages.

The error message you face is probably just caused by the android packaging into an apk, which tries to import both libraries and found a file that exists in both libs (have a look at this issue).

You can ignore that file by adding the following into the "android" block of your build.gradle:

android {
    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
    ...
}

However, be sure to properly test your project after that change.

cdehning
  • 245
  • 1
  • 4
0

You need to exclude some rx properties. Add this:

android {
...
packagingOptions {
    exclude 'META-INF/rxjava.properties'
    }
}

To your app build gradle

K.Os
  • 5,123
  • 8
  • 40
  • 95