Android Studio Gradle:错误:找不到名称为“compile”的配置

时间:2017-07-02 03:30:50

标签: android gradle

我的项目刷新失败,并显示以下gradle脚本的错误:错误:找不到名为'compile'的配置。

//顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'com.google.gms:google-services:3.1.0'

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

allprojects {
    repositories {
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.google.gms.google-services'

3 个答案:

答案 0 :(得分:11)

删除apply plugin:' com.google.gms.google-services'来自project / build.gradle并将其放入app / build.gradle

apply plugin: 'com.android.application'
android {

...
..
}

dependencies {

....
..

}

apply plugin: 'com.google.gms.google-services'

答案 1 :(得分:0)

糊 应用插件:build.gradle底部的“com.google.gms.google-services”(模块应用)和 将'com.google.firebase:firebase-core:12.0.0'编译为build.graddle(模块应用)的依赖项

删除 插件:来自build.gradle(项目名称)的“com.google.gms.google-services”

答案 2 :(得分:0)

我遇到了同样的错误,我通过移除.each{...}并将其移至底部dependencies {...}并使用前缀implementation解决了该问题:

apply plugin: 'com.android.application'

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        google()
        flatDir {
            dirs '<your_aar_directory_patj>'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-alpha12'
    }

    //[1] Don't put here !!!
}

...

//[2] Remove the below ".each{...}" part, then put it inside dependencies with prefix 'implementation':
/*
fileTree(dir: 'your_aar_directory_path', include: '**/*.aar')
.each { File file ->
dependencies.add("compile",
[name: file.name.lastIndexOf('.').with {
it != -1 ? file.name[0..<it] : file.name
}, ext: 'aar'])
}
*/

dependencies {
    implementation fileTree(dir: '<your_aar_directory_path>', include: '**/*.aar')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    ...
}

implementation fileTree(dir: '<your_aar_directory_path>', include: '**/*.aar')抑制错误。我所指的文件似乎已经过时了。