简体   繁体   English

找不到Gradle DSL方法:'compile()'-依赖项已在模块级别build.gradle中

[英]Gradle DSL method not found: 'compile()' - Dependencies are in Module level build.gradle already

Yes, I m having this Gradle DSL method not found: 'compile()' problem again. 是的,我找不到该Gradle DSL方法:再次出现“ compile()”问题。

I checked that I have : 我检查了一下:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

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

... in the {root}/build.gradle file ...在{root} /build.gradle文件中

and having ... 并有...

dependencies {
    // App's dependencies, including test
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    compile "com.google.guava:guava:$rootProject.guavaVersion"
    compile "com.github.bumptech.glide:glide:$rootProject.glideVersion"
    ...
}

... in the app/build.gradle file. ...在app / build.gradle文件中。

In fact, I am trying to get the Google example from here to work. 实际上,我正在尝试从此处获取Google示例。 It is not working out of box, having this issue. 它不是开箱即用的,有这个问题。

The gradle version is: 2.1.0 gradle版本是:2.1.0

The gradle wrapper version is: distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip Gradle包装器版本为: distributionUrl = https://services.gradle.org/distributions/gradle-2.10-all.zip

Thanks in advance, this is burning me. 在此先感谢,这让我很烦。

May be your syntax is wrong in build.gradle (App Level) for adding Dependencies. 可能是您在build.gradle (应用程序级别)中添加依赖项的语法错误。 In android studio, gradle supports Groovy based language. 在android studio中,gradle支持基于Groovy的语言。 Just try to remove double colon(""). 只需尝试删除双冒号(“”)。 For ex : 对于前:

Try this - 试试这个 -

compile 'com.android.support:appcompat-v7:$rootProject.supportLibraryVersion'

instead of 代替

compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"

Try replacing compile " " 尝试替换编译“”

with ' ' 与''

Thanks @OnkarNene and @YashJain for your suggestion, unfortunately it's not solving the problem. 感谢@OnkarNene和@YashJain的建议,不幸的是它不能解决问题。

compile ' ' and compile " " are BOTH VALID syntax. 编译''和编译“”均为有效语法。

compile " " allows you to use :${variableName} for variable look-up and replacement. 编译“”允许您使用:$ {variableName}进行变量查找和替换。

I found my solution from this post . 我从这篇文章中找到了解决方案。 The reason for this problem is when I upgrade my Android Studio, it somehow mixed up my existing repository (sorry, still not fully understand how Android Studio / Gradle / Gradle Wrapper's repository works), I solve the problem by force clean the repository, then gradle builds again. 出现此问题的原因是,当我升级我的Android Studio时,它以某种方式混淆了我现有的存储库(对不起,仍然无法完全理解Android Studio / Gradle / Gradle Wrapper的存储库的工作原理),我通过强制清理存储库解决了问题,然后gradle再次建立。

Many thanks ~ 非常感谢〜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM