android - 使用 rxjava 重复条目转换异常

标签 android rx-java

错误:任务 ':app:transformClassesWithJarMergingForDebug' 执行失败。

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: rx/Observable$23.class

这是 build.gradle 文件。

buildscript {
repositories {
    jcenter()
}

dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 23
    versionName "1.1"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),      'proguard-rules.pro'
    }
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/services/javax.annotation.processing.Processor'
}

// Enable Java 7 features (diamond operator, string switch statements, etc.)
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//    testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
apt 'com.google.dagger:dagger-compiler:2.0'
compile 'com.google.dagger:dagger:2.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup:otto:1.3.6'
compile 'com.github.frankiesardo:icepick:2.3.6'
provided 'com.github.frankiesardo:icepick-processor:2.3.6'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'org.parceler:parceler:0.2.9'
compile 'com.netflix.rxjava:rxjava-android:0.20.7'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.jakewharton:butterknife:5.1.2'
compile 'io.reactivex:rxjava-computation-expressions:0.21.0'
}

最佳答案

问题

compile 'com.netflix.rxjava:rxjava-android:0.20.7' //Problem Here

compile 'io.reactivex:rxjava-computation-expressions:0.21.0'

调用 io.reactivex 而不是 com.netflix.rxjava

最后

compile  'io.reactivex.rxjava2:rxjava:2.0.1'
compile  'io.reactivex:rxjava-computation-expressions:0.21.0'

然后Clean-Rebuild & Run

编辑

你应该使用最新的稳定版本

compileSdkVersion 25
buildToolsVersion "25.0.1"
targetSdkVersion 25
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'

关于android - 使用 rxjava 重复条目转换异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41927441/

相关文章:

android - RxJava Observable 从不执行 onCompleted

java - Android 创建 xml 并将其写入文件

android - Android Studio 中过时的 Kotlin 运行时警告

Android应用程序图标更改

java - 如何将 HTML 从数字转换为文字

android - 使用 Retrofit 2 和 Rx 在 Scheduler.Worker 线程上抛出致命异常

android - 如何在 Android 上使用 iText 或其他库创建 PDF 文件?

asynchronous - 发生某些情况时如何停止 Kotlin 流程

java - Observable.just(doSomeLongStuff()) 在订阅 observable 之前运行 doSomeLongStuff()

rx-java - RxJava 使用 autoConnect 处理 ConnectableObservable