android - Gradle DSL 方法未找到 : 'compile()'

标签 android

我遇到了这个 gradle 错误。

Error:(9, 0) Gradle DSL method not found: 'compile()'

我曾尝试引用类似的问题,但没有奏效。

Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.

Getting Error "Gradle DSL method not found: 'compile()'" when Syncing Build.Gradle

Unsupported Gradle DSL method found: 'compile()'!

我的 build.gradle 代码在这里

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

allprojects {
    repositories {
        jcenter()
    }
}

build.gradle(Module.app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.example.simplemaker.pushtest"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

我的代码有什么问题?

最佳答案

正如您项目的 build.gradle 文件的注释所示:

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

删除该 gradle 文件中的 2 个编译语句:

compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:6.5.+'

然后让你的其他(模块的)build.gradle 依赖项看起来像这样:

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

关于android - Gradle DSL 方法未找到 : 'compile()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27617687/

相关文章:

java - 使用可滑动的选项卡更改单个 fragment 中的数据

java - 如何清除android中的后台进程?

android - 可以使用 Espresso 测试小部件

Android LVL 自定义许可期限

java - 绘制基于图 block 的 map

Android Gallery - 缓存请求刷新

java - 我如何在Android中分割文件 Case 文件很大上传它(声音文件)

java - 如何使用java检查24H是否已经过去?

c# - 如何在 xamarin 中从 Syncfusion 绑定(bind) SfMaskedEdit?

android - Android 中用于 EditText 的 InputFilter 的正则表达式帮助