【问题标题】:Error:(9, 0) Could not find method compile() for arguments [io.reactivex:rxandroid:1.2.1]错误:(9, 0) 找不到参数 [io.reactivex:rxandroid:1.2.1] 的方法 compile()
【发布时间】:2017-07-24 09:56:17
【问题描述】:

当我同步我的 android studio 项目时,它得到 错误:(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
}

【问题讨论】:

    标签: android reactive-programming


    【解决方案1】:

    您在错误的部分调用此库。有两种build.gradle 文件。欲了解更多信息build.gradle

    为了解决问题,你应该在模块级别的build.gradle中添加所需的依赖项,确切地说是app\build.gradle

    从根 '`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'
        }
    

    仅供参考

    最好用最新版,

    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.0.1'
    

    【讨论】:

    • 当我在 build.gradle 模块级别添加它时,它会出现错误无法解决:io.reactivex:rxjava:1.1.9
    • 错误(29,13)和错误(28,13):禁用离线模式和同步显示在项目结构对话框中的文件显示
    • @DipuKumar 点击Disable offline mode and Sync show 和gradle
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-29
    • 2022-01-23
    • 2017-10-01
    • 1970-01-01
    相关资源
    最近更新 更多