无法使用 gradle 3.0 解析 rxjava2

Cannot resolve rxjava2 with gradle 3.0

Hare 是我的应用gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.atumanin.testandroidannotations"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.1.18"

        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'io.reactivex.rxjava2:rxjava:2.1.6'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
}

这是我的项目gradle:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

如果我尝试构建项目,出现错误:

Could not resolve io.reactivex.rxjava2:rxjava:2.1.6.

Could not resolve io.reactivex.rxjava2:rxandroid:2.0.1.

我尝试清理、重建项目并使缓存失效。没有任何帮助。我还尝试使用 compile 而不是 implementation。我也尝试了两个库的不同版本,也没有成功。

它会报错,因为 rxjava 的官方版本是 2.1.5

只需更改以下代码行

implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'

Official documentation

我找到了解决方案。问题是我的代理,它阻止了 https,我需要使用 http 版本的存储库。所以而不是:

repositories {
        jcenter()
    }

我现在用:

repositories {
        jcenter {
            url "http://jcenter.bintray.com/"
        }
    }

现在可以编译了。

只需尝试取消选中

中的离线模式

Settings -> Gradle

然后尝试 again.That 对我有用

改变

implementation 'io.reactivex.rxjava2:rxjava:2.1.6'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

api 'io.reactivex.rxjava2:rxjava:2.x.x'
api 'io.reactivex.rxjava2:rxandroid:2.0.1'

对我有用

@link https://github.com/ReactiveX/RxAndroid

// 因为RxAndroid版本少,推荐你也 // 明确依赖于 RxJava 的最新版本来修复错误和增加新功能。 //(最新 3.x.x 版本参见 https://github.com/ReactiveX/RxJava/releases

// Step 1 : in side build.gradle(Module:app)
 implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Step 2 : in side build.gradel(Project:ProjectName)  
 allprojects {
repositories {
    google()
    jcenter()
    maven { url "https://jitpack.io" }
    jcenter {
        url "http://jcenter.bintray.com/"
    }
   }
}