【问题标题】:Android Studio Gradle : Error:Configuration with name 'compile' not foundAndroid Studio Gradle:错误:找不到名称为“编译”的配置
【发布时间】:2018-04-30 15:51:48
【问题描述】:

我的项目刷新失败,出现以下 gradle 脚本的错误:错误:找不到名称为“编译”的配置。

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

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'

【问题讨论】:

  • 你能展示你的应用程序吗
  • 你显示错误的gradle.....

标签: android gradle


【解决方案1】:

从 project/build.gradle 中删除 apply plugin: 'com.google.gms.google-services' 并将其放入您的 app/build.gradle

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

...
..
}

dependencies {

....
..

}

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

【讨论】:

  • 我已经尝试过了,但它仍然给我同样的错误。
  • 对不起,我没有看到你的 app/build.gradle 和 project/build.gradle。尝试使用您的构建 gradles 观看其他答案或提出新问题。
  • 嘿,你能解决问题吗?我也面临同样的问题。如果您知道解决方案,请告诉我?
【解决方案2】:

粘贴 在 build.gradle(module app) 底部应用插件:'com.google.gms.google-services' 和 将 'com.google.firebase:firebase-core:12.0.0' 编译成 build.graddle(module app) 的依赖项

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

【讨论】:

  • 赞成!这是我的问题。谢谢!
【解决方案3】:

我遇到了同样的错误,我通过删除 .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: '&lt;your_aar_directory_path&gt;', include: '**/*.aar') 抑制错误。我参考的文档似乎已经过时了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 2013-06-15
    • 2014-05-09
    • 1970-01-01
    • 2015-09-29
    • 2013-05-11
    相关资源
    最近更新 更多