发现不受支持的 Gradle DSL 方法:'compile()'! [英] Unsupported Gradle DSL method found: 'compile()'!

查看:28
本文介绍了发现不受支持的 Gradle DSL 方法:'compile()'!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关 Android Studio 中将 Google Play 服务添加到您的项目"的 Google 文档:https://developer.android.com/google/play-services/setup.html

I'm going through Google's documentation on "Add Google Play Services to Your Project" in Android Studio: https://developer.android.com/google/play-services/setup.html

我正在使用该文档来修改新创建的 Android 项目的 build.gradle 文件.在第 2 步(将 Google Play 服务添加到您的项目)中,它指出:

I'm using that documentation to modify the build.gradle file of a freshly created Android project. In Step 2 (Add Google Play Services to Your Project), it states:

添加这一行:

apply plugin: 'android'

在依赖项下,添加:

compile 'com.google.android.gms:play-services:5.0.77'

它还说在更新 Google Play 服务后更新该版本,根据 Android SDK 管理器现在是 18.

It also says to update that version after updating Google Play Services, which is now at 18 according to Android SDK Manager.

这是我在顶层的整个 build.gradle 文件(此文件的父文件是根文件夹).

Here is my entire build.gradle file at the top-level (parent of this file is the root folder).

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'android'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
        compile 'com.google.android.gms:play-services:18'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

保存后,它会提示进行同步.我同步它,但得到:

Upon saving, it prompts for a Sync. I Sync it, but get:

Build script error, unsupported Gradle DSL method found: 'compile()'!

Error:(10, 0) Possible causes could be:
              - you are using a Gradle version where the method is absent
              - you didn't apply Gradle plugin which provides the method
              - or there is a mistake in a build script

我使用的是 Android Studio 0.8.2.我没有安装 Gradle,只是使用 Android Studio 自带的插件.

I'm using Android Studio 0.8.2. I didn't install Gradle, just using the plugin that came with Android Studio.

有趣的是,我创建这个新项目时生成的 build.gradle 文件说:

It's interesting to note that the build.gradle file generated when I made this new project says:

//NOTE: Do not place your application dependencies here

但谷歌的文档说(与上述冲突):

But Google's documentation says (which conflicts with the above):

Note: Android Studio projects contain a top-level build.gradle file and a build.gradle
      file for each module. Be sure to edit the file for your application module.

我的 build.gradle 文件(或环境)有什么问题?

What's wrong with my build.gradle file (or environment)?

推荐答案

您引用的 Google 文档是正确的,没有冲突.有不止一个 build.gradle 文件.与其将依赖项放在顶层,不如将它们放在模块目录中的构建文件中.

The Google documentation you quoted is correct, and doesn't conflict. There's more than one build.gradle file. Instead of putting dependencies in the top-level one as you have, put them in the build file that's in your module's directory.

此外,不要在该顶级构建文件中放置 apply plugin: 'android' 语句;它会导致错误.

Also, don't put an apply plugin: 'android' statement in that top-level build file; it will cause an error.

您还可以通过 Project Structure UI 添加依赖项,这样做是正确的.

You can also add dependencies through the Project Structure UI, which does the right thing.

这篇关于发现不受支持的 Gradle DSL 方法:'compile()'!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆