')编译(':找到不受支持的摇篮DSL方法! [英] Unsupported Gradle DSL method found: 'compile()'!

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

问题描述

我会通过谷歌的文档添加谷歌Play服务您的项目,在Android的工作室:
<一href=\"https://developer.android.com/google/play-services/setup.html\">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

我使用的文档修改刚创建的Andr​​oid项目的的build.gradle文件。在步骤2中(谷歌添加播放服务到您的项目),它规定:

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'

根据依赖关系,补充一点:

Under Dependencies, add this:

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

它还说,谷歌更新根据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。我没有安装摇篮,只是用了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)?

推荐答案

你报的谷歌文档是正确的,并不冲突。有多个的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.

另外,不要把一个应用插件:'机器人'在顶层生成文件说明;它会导致错误。

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

您还可以通过项目结构UI,这确实是正确的添加依赖。

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

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

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