无法使用gradle 3.0解析rxjava2

问题描述 投票:6回答:4

野兔是我的应用程序:

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。我也试过了两个库的不同版本,也没有成功。

android android-gradle rx-android rx-java2
4个回答
2
投票

它会给出错误,因为rxjava的官方发布是2.1.5

只需更改下面的代码行

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

Official documentation


0
投票

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

repositories {
        jcenter()
    }

我现在用:

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

它现在编译。


0
投票

更改

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'

为我工作


-1
投票

只是尝试取消选中您的离线模式

设置 - > Gradle

然后再试一次。这对我有用

© www.soinside.com 2019 - 2024. All rights reserved.