野兔是我的应用程序:
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'
我找到了解决方案。问题是我的代理,它阻止了https
,我需要使用http
版本的存储库。所以代替:
repositories {
jcenter()
}
我现在用:
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
它现在编译。
更改
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'
为我工作
只是尝试取消选中您的离线模式
设置 - > Gradle
然后再试一次。这对我有用