本文介绍了同一项目中的RxJava 1和RxJava 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们的项目使用RxJava 1:
Our project uses RxJava 1:
compile 'io.reactivex:rxjava:1.1.6'
我们使用一个内部使用RxJava 2的库:
There is a library we use that uses RxJava 2 internally:
compile 'io.reactivex.rxjava2:rxjava:2.0.9'
当我执行 ./gradlew assembleDebug
时,出现此错误:
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
我认为可以同时使用RxJava 1和RxJava 2,为什么我仍然遇到此错误?
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?
推荐答案
运行时不需要rxjava.properties文件.
rxjava.properties file is not required at run time.
因此,您可以在打包android应用时排除该文件,方法是在app/build.gradle文件中设置PackagingOptions,如下所示.
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**'
}
}
这篇关于同一项目中的RxJava 1和RxJava 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!