buildTypes cannot be applied to groovy.lang.Closure

前端 未结 19 2046
故里飘歌
故里飘歌 2020-11-27 11:31

I\'m getting this warning in my project gradle file:

Warning:(16, 5) \'buildTypes\' cannot be applied to \'(groovy.lang.Closure< com.android.build.

相关标签:
19条回答
  • I had the same issue. Moving the buildTypes as the last entry in the android section worked for me.

    android {
        ...
        buildTypes {
        }
    }
    
    0 讨论(0)
  • 2020-11-27 12:01

    delete gradle folder under the app folder and resync project

    0 讨论(0)
  • 2020-11-27 12:04

    this worked for me:

    buildTypes.debug {
        ext.enableCrashlytics = false
    }
    
    buildTypes.release {
        debuggable false
        zipAlignEnabled true
        minifyEnabled false
        signingConfig signingConfigs.release
    }
    
    0 讨论(0)
  • 2020-11-27 12:04

    EDIT: This how i finally solved this problem...

    1. Navigate in Android Studio to:

      File | Settings | Build, Execution, Deployment | Build Tools | Gradle

    2. Ensure that this is unchecked, despite that it is recommended to keep ...

      Use Default Gradle Wrapper (recommended)

    3. and that this one is checked ...

      Use local gradle distribution

    4. and that Gradle Home is set to this, with possibly a later gradle-n.n ...

      C:/Program Files/Android/Android Studio1/gradle/gradle-2.4

    You may have to restart Android Studio, rebuild the project, etc but the problem is solved.

    End of EDIT.

    I am posting this to advise anyone else new to this problem to ignore it. The project runs perfectly regardless. This is quite simply a bug in the build system, hopefully to be fixed soon. I posted a comment and voted here where it is again an active topic ...

    https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=76719

    After trying, unsuccessfully, the suggestions in the following three threads, i re-made the entire project from scratch. I started a new Android Studio project, copied all of the original libs and main files into it ignoring any files which are generated by the build system and rebuilt the project. Everything was fine except all those "cannot be applied to '(groovy.lang.Closure)'" warnings re-appeared with a vengence. Then i went thru these suggestions again just to be certain that i had not overlooked something.

    1 buildTypes cannot be applied to groovy.lang.Closure go to the settings within Android Studio and select "Use gradle wrapper": In Android Studio select: File\Settings\Build, Execution, Deployment\Build tools\Gradle Mark: Use default gradle wrapper (default) This removed all 'cannot be applied to '(groovy.lang.Closure') warnings in the build files.

    2 'dependencies' cannot be applied to '(groovy.lang.Closure)' Open and edit file: yourproject/gradle/wrapper/gradle-wrapper.propertie. Edit content as below image then save. Delete this folder: yourproject/.gradle. Click Sync project with gradle files, then you are good to go.

    3 https://github.com/DrKLO/Telegram/issues/870

    My configuration is: Android Studio 1.3, compileSdk Version 22, buildTools Version "22.0.1"

    0 讨论(0)
  • 2020-11-27 12:05

    The problem presents when you import a project into your environment and the Gradle plugin is installed in a different location than what it was in the original. You just need to point out where your Gradle installation is.

    Moving buildTypes or defaultConfig or whatever between each other is not a complete solution

    0 讨论(0)
  • 2020-11-27 12:05

    All I had to do to remove

    productFlavors {
    }
    

    From

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

    and the warning went away.

    Final look was like this

    buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题