Android gradle 构建错误:(9, 0) Gradle DSL 方法未找到:'compile()'. [英] Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.

查看:41
本文介绍了Android gradle 构建错误:(9, 0) Gradle DSL 方法未找到:'compile()'.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试同步我的项目时出现以下构建错误:

I am getting the following build error when I try and sync my project:

Error:(9, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'AlexTest' may be using a version of Gradle that does not contain the method.
The build file may be missing a Gradle plugin.
link: Apply Gradle plugin

我已经尝试在底部的那个链接中应用他们链接到我的每一个 gradle 插件,但同样的问题,所以我得出结论,第一个错误是原因.

I have tried applying every single gradle plugin they link me to in that link on the bottom, yet same issue, so I conclude that the first error is the cause.

这是 AlexTest 的 build.gradle 文件(项目目录):

Here is the build.gradle file for AlexTest (the project directory):

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.13.2'
        compile 'com.google.android.gms:play-services:6.1.11'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

我认为这是它遇到问题的 gradle 文件.但我不确定它指的是什么方法.

I think that was the gradle file it was having trouble with. But I'm not sure what method it is referring to.

这里还有 gradle-wrapper.properties ,它也提到了:

Also here is the gradle-wrapper.properties which it also referred to:

#Mon Nov 10 01:06:12 PST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-2.1-all.zip

也许 distributionUrl 中的 gradle 版本需要匹配依赖项中的版本?

perhaps the gradle version in the distributionUrl needs to match the one in the dependency?

我在 app 目录中也有一个 build.gradle 文件 - 低 1 级,虽然我认为这不是它所指的,但它是:

I also have a build.gradle file in the app directory itself - 1 level lower, though I don't think that is what it was referring to, but here it is:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.snappiesticker.alextest"
        minSdkVersion 16
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:6.1.+'
}

推荐答案

我已经尝试在底部的那个链接中应用他们链接到我的每一个 gradle 插件,但同样的问题,所以我得出结论,第一个错误是原因.

I have tried applying every single gradle plugin they link me to in that link on the bottom, yet same issue, so I conclude that the first error is the cause.

正确.

这是 AlexTest 的 build.gradle 文件(项目目录):

Here is the build.gradle file for AlexTest (the project directory):

你会注意到这个文件包含一个代码注释:

You will notice that this file contains a code comment:

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

从该文件中删除 compile 'com.google.android.gms:play-services:6.1.11' 行.将 compile 'com.google.android.gms:play-services:6.1.+' 保留在另一个 build.gradle 文件中.

Remove the compile 'com.google.android.gms:play-services:6.1.11' line from that file. Leave the compile 'com.google.android.gms:play-services:6.1.+' that you have in the other build.gradle file.

buildscript 中的 dependencies 闭包仅适用于 Gradle 插件.顶层 dependencies 闭包位于模块的 build.gradle 文件中,用于应用程序依赖项.

The dependencies closure in buildscript is for Gradle plugins only. The top-level dependencies closure, found in the module's build.gradle file, is for application dependencies.

这篇关于Android gradle 构建错误:(9, 0) Gradle DSL 方法未找到:'compile()'.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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