RxJava 1 and RxJava 2 in the same project [duplica

2020-04-16 03:32发布

Our project uses RxJava 1:

compile 'io.reactivex:rxjava:1.1.6'

There is a library we use that uses RxJava 2 internally:

compile 'io.reactivex.rxjava2:rxjava:2.0.9'

When I do ./gradlew assembleDebug I get this error:

com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
      File1: /Users/darklord/.gradle/caches/modules-2/files-2.1/io.reactivex/rxjava/1.1.6/2586312cd2b8a511e4c6236736f5a039fc0f2273/rxjava-1.1.6.jar
      File2: /Users/darklord/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.0.9/a5aad74623ade11162dd53cdf0645a51b12221a0/rxjava-2.0.9.jar

I think it is said that RxJava 1 and RxJava 2 can be used at the same time, why I am still getting this error?

1条回答
神经病院院长
2楼-- · 2020-04-16 03:40

rxjava.properties file is not required at run time.

So you can exclude the file while packaging your android app by setting packagingOptions in app/build.gradle file as shown below.

android {
    ...
    packagingOptions {
        exclude 'META-INF/**rxjava.properties**'
    }
}
查看更多
登录 后发表回答