找不到方法编译()

Could not find method compile()

我想在 android 工作室中添加一个库,但它不起作用。 这是截图

我也尝试在 gradle.build 中添加依赖项,但这也不起作用。也许是因为我在代理后面?

使用了错误的 build.gradle 文件。

您不能在顶级文件中使用 compile
使用 module/build.gradle.

<PROJECT_ROOT>\app\build.gradle 特定于 应用程序模块

<PROJECT_ROOT>\build.gradle 是一个 "Top-level build file",您可以在其中添加所有 sub-projects/modules.

通用的配置选项

此外,您应该将库包含在 dependencies 块中,而不是在 buildscript 块中。

顶级文件示例:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
       classpath 'com.android.tools.build:gradle:2.3.0'
       classpath 'com.google.gms:google-services:3.0.0'
    }
}

app\build.gradle 中,您只定义模块的属性:

apply plugin: 'com.android.application'


android {
    compileSdkVersion ...
    buildToolsVersion ...
}

dependencies {
    //..... HERE !
}