当我同步我的android工作室项目时,它得到了 错误:(9,0)无法在类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
的对象上找到参数[io.reactivex:rxandroid:1.2.1]的方法compile()我的build.gradle文件位于
之下// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.9'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案 0 :(得分:2)
您在错误的部分调用此库。有两种build.gradle
文件。有关详情 build.gradle
为了解决这个问题,您应该在模块级别的build.gradle
中添加所需的依赖项,确切地说是 app \ build.gradle
从root“build.gradle”中删除依赖项,并将其粘贴到 app \ build.gradle 中。
android {
compileSdkVersion // YOURS
buildToolsVersion // YOURS
...........
}
dependencies {
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.9'
}
<强> FYI 强>
最好使用最新版本
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'