'dependencies'不能应用于'(groovy.lang.Closure)'

Ash*_*lli 120 groovy android gradle

我无法修复此错误:

dependencies cannot be applied to '(groovy.lang.Closure)
Run Code Online (Sandbox Code Playgroud)

这是我的gradle文件:

buildscript {
     repositories {
         maven { url 'http://download.crashlytics.com/maven' }
     }

     dependencies {
         classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
     }
 }
apply plugin: 'android'
apply plugin: 'crashlytics'

repositories {
   maven { url 'http://download.crashlytics.com/maven' }
}

dependencies {
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':FRNDzTER_core')
    compile project(':cropper')
    compile project(':stickyListHeaders')
    compile "com.nostra13.universalimageloader:universal-image-loader:${rootProject.universalImageLoaderVersion}"
    compile "com.google.android.gms:play-    services:${rootProject.googlePlayServicesVersion}"
    compile "de.keyboardsurfer.android.widget:crouton:${rootProject.croutonVersion}"
    compile "com.nineoldandroids:library:${rootProject.nineoldandroidsVersion}"
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
    compile 'com.crashlytics.android:crashlytics:1.+'
}

android{
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode rootProject.versionCode
        versionName rootProject.versionName
    } 
    buildTypes {
        release {
            debuggable rootProject.prodDebug
            proguardFile 'proguard.cfg'
        }
    }

    dependencies {
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    lintOptions {
        abortOnError false
    }
 }
Run Code Online (Sandbox Code Playgroud)

cod*_*uss 247

您可以转到"首选项"并选择"使用默认gradle包装器",然后重建项目.它对我很有用: 在此输入图像描述

  • 有没有人解释为什么会这样? (4认同)
  • @EpicPandaForce请将此标记为正确答案 (4认同)
  • 截至143.2532994版本,这个问题似乎再次发生......任何人都跟我一样......?很烦人.. (3认同)

Mar*_*zon 37

视窗

文件 - >设置 - >构建,执行,部署 - >构建工具 - > Gradle

苹果电脑

首选项 - >构建,执行,部署 - >构建工具 - > Gradle

并选择使用默认gradle包装器

  • 首先,您必须先打开项目. (2认同)

Epi*_*rce 22

根据Android Studio生成的内容,您需要拥有一个顶级项目文件build.gradle,另一个适用于您的应用build.gradle.

顶层:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven { url 'http://download.crashlytics.com/maven' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'http://download.crashlytics.com/maven' }
    }
}
Run Code Online (Sandbox Code Playgroud)

申请级别:

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

android{
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode rootProject.versionCode
        versionName rootProject.versionName
    } 
    buildTypes {
        release {
            debuggable rootProject.prodDebug
            proguardFile 'proguard.cfg'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    lintOptions {
        abortOnError false
    }
 }     `

dependencies {
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':FRNDzTER_core')
    compile project(':cropper')
    compile project(':stickyListHeaders')
    compile "com.nostra13.universalimageloader:universal-image-          l                        loader:${rootProject.universalImageLoaderVersion}"
    compile "com.google.android.gms:play-    services:${rootProject.googlePlayServicesVersion}"
    compile "   "de.keyboardsurfer.android.widget:crouton:${rootProject.croutonVersion}"
    compile "com.nineoldandroids:library:${rootProject.nineoldandroidsVersion}"
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
    compile 'com.crashlytics.android:crashlytics:1.+'
}
Run Code Online (Sandbox Code Playgroud)

但即使没有这一切,你的问题是dependencies你的android插件配置中有一个.

android {
    dependencies {
    }
}
Run Code Online (Sandbox Code Playgroud)

删除那个空dependencies块.

编辑:我也开始使用最新的Android Studio收到此错误,我所要做的就是添加更新版本的Gradle插件和compileSdkVersion 22.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'

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

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 我做的仍然是同样的问题:( (11认同)

Ars*_*rst 18

我的问题是整个build.setting文件都被cannot be applied to '(groovy.lang.Closure)'警告消息占用,而不是发生在任何特定变量上.

我尝试过其他人提供的所有解决方案,但它们都不适合我.我结束了这些步骤,然后它就像一个魅力.如果您遇到同样的问题,请尝试一下.

  1. 打开并编辑文件:yourproject/gradle/wrapper/gradle-wrapper.properties.编辑内容以更新gradle分发版本,如下图所示,然后保存.
  2. 删除此文件夹:yourproject/.gradle.
  3. 点击Sync project with gradle files,然后你很高兴.

在此输入图像描述


And*_*rey 18

如果您已经使用"默认gradle包装器"并且它没有帮助:

In Menu click: File -> Invalidate Caches / Restart...
Run Code Online (Sandbox Code Playgroud)

如果它也没有帮助尝试分两步:

1) Delete ".gradle" folder (and "build" folder if you have it already)

2) In Menu click: File -> Invalidate Caches / Restart...
Run Code Online (Sandbox Code Playgroud)

重新启动后警告应该消失.

(对我而言,它适用于Android Studio和IntelliJ Idea)

  • 只是做 2) 指令对我有用。谢谢!! (2认同)
  • 工作...持续5秒.然后我又得到了那个错误. (2认同)