'dependencies' cannot be applied to '(groovy.lang.Closure)'

AndroidGroovyGradle

Android Problem Overview


I am unable to fix this error:

dependencies cannot be applied to '(groovy.lang.Closure)

This is my gradle file:

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
    }
 }

Android Solutions


Solution 1 - Android

You can go to Preferences and select "use default gradle wrapper" then rebuild the project. It worked well for me: enter image description here

Solution 2 - Android

Go to

Windows

File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle

Mac

Preference -> Build, Execution, Deployment -> Build Tools -> Gradle

and select Use default gradle wrapper

Solution 3 - Android

Based on what Android Studio generates, you need to have a top-level project file build.gradle, and another for your app build.gradle.

Top-level:

// 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' }
    }
}

Application level:

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.+'
}

But even without all that, your problem is that you have a dependencies within your android plugin config.

android {
    dependencies {
    }
}

remove that empty dependencies block.

EDIT: I also started getting this error with the latest Android Studio, all I had to do was add a newer version of the Gradle plugin, and 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()
    }
}

Solution 4 - Android

If you already are using the "default gradle wrapper" and it doesn't help:

In Menu click: File -> Invalidate Caches / Restart...

If it also doesn't help try in 2 steps:

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

2) In Menu click: File -> Invalidate Caches / Restart...

After restarting the warning should disappear.

(For me it worked and for Android Studio and for IntelliJ Idea)

Solution 5 - Android

My problem is that the whole build.setting file were occupied with cannot be applied to '(groovy.lang.Closure)' warning messages instead of happening on any particular variable.

I have tried all solutions provided by others but none of them works for me. I ended out doing these steps then it works like a charm. If you are encountering the same issue then give it a try.

  1. Open and edit file: yourproject/gradle/wrapper/gradle-wrapper.properties. Edit content to update the gradle distribution version as shown in the image below then save.
  2. Delete this folder: yourproject/.gradle.
  3. Click Sync project with gradle files, then you are good to go.

enter image description here

Solution 6 - Android

I went into the preferences to try one of the other answers when I noticed a warning that my gradle home directory was wrong. So I opened up the file browser and chose the newer gradle version, and all the errors went away. Image shown below.

enter image description here

Solution 7 - Android

I bet you the problem is totally unrelated to the piece of code that is giving you warnings, most likely it's your proguard file. I had the following in my code and got the same warning:

buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

By commenting out runProguard false, all of my problems go away, go figure :)

Solution 8 - Android

I have same problem in android studio 2.2,it work for me:

original:

android {
...
}

dependencies {
...
}

move dependencies in android:

android {
...
   dependencies {
   ...
   }
}

Solution 9 - Android

I solved the problem in Android Studio by Invalidating the cache and restart.

File-> Invalidate Caches / Restart..

enter image description here

Solution 10 - Android

I ran into a similar problem to this in IntelliJ for a Kotlin project. It looks like the issue was that in my project, even though it was set to use JDK 8, the language and API versions somehow got set to 1.3. See Project Preferences > Facets. In my case, I ticked "use project settings," but manually setting them per facet may work as well.

Solution 11 - Android

  1. Close the project (File / Close project),
  2. Select “Open an existing Android Studio project” on the start menu and select the folder that contains your Android project.

This work for me.

Solution 12 - Android

Gradle files can be made explicit in several places to avoid such errors. E.g. Change

configurations {

to

project.configurations {

or

task {
    description 'foo'

to

task {
    setDescription 'foo'

Solution 13 - Android

To fix the issue simply close the project, then select “Open an existing Android Studio project” on the start menu and select the folder that contains your Android project. Beware, select the folder, not the .iml project file.

Solution 14 - Android

Cut and then paste the "buildTypes" at the same place in "android" section and Re-Sync (refresh) Project

Solution 15 - Android

For people with M1 Intellij IDEA just add in build.gradle(:app)

//noinspection GroovyAssignabilityCheck

buildFeatures {
        viewBinding
    }

Solution 16 - Android

I fixed this issue with gradle 2.10.

Download it here : http://gradle.org/gradle-download/

And set your local gradle distribution like this :

as shown here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAshwani KottapalliView Question on Stackoverflow
Solution 1 - AndroidDũng Trần TrungView Answer on Stackoverflow
Solution 2 - AndroidMark PazonView Answer on Stackoverflow
Solution 3 - AndroidEpicPandaForceView Answer on Stackoverflow
Solution 4 - AndroidAndrewView Answer on Stackoverflow
Solution 5 - AndroidArstView Answer on Stackoverflow
Solution 6 - AndroidcranedView Answer on Stackoverflow
Solution 7 - AndroidDaniel WilsonView Answer on Stackoverflow
Solution 8 - AndroidYakamiView Answer on Stackoverflow
Solution 9 - AndroidahmadalibalochView Answer on Stackoverflow
Solution 10 - AndroidTim KeatingView Answer on Stackoverflow
Solution 11 - Androidzerob13View Answer on Stackoverflow
Solution 12 - AndroidtkruseView Answer on Stackoverflow
Solution 13 - AndroidWebdmaView Answer on Stackoverflow
Solution 14 - AndroidAndrewView Answer on Stackoverflow
Solution 15 - AndroidFelipe FrancoView Answer on Stackoverflow
Solution 16 - Androidmichael crusemView Answer on Stackoverflow