【问题标题】:ERROR: Gradle DSL method not found: 'compile()'错误:未找到 Gradle DSL 方法:'compile()'
【发布时间】:2019-11-04 15:29:38
【问题描述】:

我正在尝试使用 yelp-fusion-android 库。我尝试更新 gradle 但没有成功。

我收到此错误:

ERROR: Gradle DSL method not found: 'compile()'
Possible causes:
The project 'testProject' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file

The build file may be missing a Gradle plugin.
Apply Gradle plugin

这里是 build.gradle:

buildscript {
repositories {
    google()
    jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.5.1'
    classpath 'com.google.gms:google-services:4.3.2'
    compile 'io.github.ranga543:yelp-fusion-client:0.1.4'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

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

【问题讨论】:

标签: java android api gradle


【解决方案1】:

顶级文件中删除这一行:

//compile 'io.github.ranga543:yelp-fusion-client:0.1.4'

app/build.gradle文件中你可以添加同样的依赖:

dependencies {
    ...
    implementation 'io.github.ranga543:yelp-fusion-client:0.1.5'
    ...
}

【讨论】:

    【解决方案2】:

    你的问题就在这里 编译'io.github.ranga543:yelp-fusion-client:0.1.4'

    编译不推荐使用“实现”代替

    并且您将其放置在错误的 gradle 中,有 2 个 gradle 文件 请注意这个警告 // 注意:不要将您的应用程序依赖项放在这里;他们属于 // 在单个模块 build.gradle 文件中

    【讨论】:

      【解决方案3】:

      将以下依赖项放在 app 模块而不是主项目 gradle 中。

      compile 'io.github.ranga543:yelp-fusion-client:0.1.4'
      

      并将编译替换为实现。 例如(在 app 模块中)

      Implementation 'io.github.ranga543:yelp-fusion-client:0.1.4'
      

      【讨论】:

        【解决方案4】:

        buildscript 中的dependencies 部分不适用于模块依赖项。因此。从本节中移出compile 'io.github.ranga543:yelp-fusion-client:0.1.4' 并创建顶级依赖项块并将其放在那里,如下所示:

        buildscript {
        repositories {
            google()
            jcenter()
        
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.1'
            classpath 'com.google.gms:google-services:4.3.2'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
            }
        }
        
        allprojects {
            repositories {
                google()
                jcenter()
        
            }
        }
        
        task clean(type: Delete) {
            delete rootProject.buildDir
        }
        
        dependencies {
            compile 'io.github.ranga543:yelp-fusion-client:0.1.4'
            }
        

        另外,如果你有子模块,那么你可以将这个依赖添加到子模块中。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-03-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-11-19
          • 2015-02-21
          • 2017-12-10
          • 1970-01-01
          相关资源
          最近更新 更多