【发布时间】:2014-09-03 23:46:45
【问题描述】:
我正在浏览 Google 在 Android Studio 中关于“将 Google Play 服务添加到您的项目”的文档: https://developer.android.com/google/play-services/setup.html
我正在使用该文档来修改新创建的 Android 项目的 build.gradle 文件。在第 2 步(将 Google Play 服务添加到您的项目)中,它声明:
添加这一行:
apply plugin: 'android'
在依赖项下,添加:
compile 'com.google.android.gms:play-services:5.0.77'
它还说在更新 Google Play 服务后更新该版本,根据 Android SDK 管理器,该版本现在为 18。
这是我在顶层的整个 build.gradle 文件(该文件的父级是根文件夹)。
// 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()
}
}
保存后,它会提示进行同步。我同步它,但得到:
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 自带的插件。
有趣的是,我创建这个新项目时生成的 build.gradle 文件显示:
//NOTE: Do not place your application dependencies here
但谷歌的文档说(与上述冲突):
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 文件(或环境)有什么问题?
【问题讨论】:
标签: gradle android-studio