如何解决未找到的错误Gradle DSL方法:“ compile()”?

时间:2019-07-18 12:41:05

标签: android android-studio android-gradle build.gradle

我正在尝试将google play计费库与我的android应用程序集成,当我尝试在应用模块的(compile 'com.android.billingclient:billing:1.0')文件中添加此依赖项build.gradle时。我收到以下错误:

ERROR: Gradle DSL method not found: 'compile()'

Possible causes:
The project 'work' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.4.1 and sync project

The project 'work' 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

有人可以帮忙吗?

已经感谢。

2 个答案:

答案 0 :(得分:5)

转到 Build.gradle(Module:App)

image

dependencies {
    implementation 'com.android.billingclient:billing:1.0'
}

答案 1 :(得分:1)

以下依赖项不应添加到顶级gradle中

compile 'com.android.billingclient:billing:1.0'

将其添加到应用模块gradle中。

不建议使用compile关键字,现在您可以在新版本下使用

implementation 'com.android.billingclient:billing:1.0'