buildTypes cannot be applied to groovy.lang.Closure

前端 未结 19 2049
故里飘歌
故里飘歌 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条回答
  • 2020-11-27 12:12

    Changing the buildToolsVersion from

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2" 
    .. 
    }
    

    to

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.1" 
    .. 
    }
    

    worked for me.

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

    The easiest way to fix this Gradle issues is recreating the project to let Android Studio reconfigure Gradle.

    Simply select "Open an existing Android Studio project" and pick your project folder.

    More details here.

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

    I managed to solve my issue by simply doing this: Click "File" then select "Invalidate Caches/ Restart

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

    The issue at hand is that your Android Studio settings that you probably imported at upgrade, was still pointing to gradle-2.4 or some other versions than Android Studio 1.5 expects.

    To solve this problem, you should open up Settings and go to Build, Execution, Deployment > Build Tools > Gradle and change your local gradle distribution's home path or select the default gradle wrapper.

    Apply and re-sync your project.

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

    In my case my buildTypes section was above my productFlavors section. Interchanging their positions got rid of the warning:

    BEFORE:

    buildTypes {
    
            debug {
                minifyEnabled false
                shrinkResources false
                ...//etc
            }
     }
    
     productFlavors {
        demo {
            ...//etc
        }
     }
    

    AFTER:

     productFlavors {
        demo {
            ...//etc
        }
     }    
    
     buildTypes {
    
            debug {
                minifyEnabled false
                shrinkResources false
                ...//etc
            }
     }
    

    I am using Android Studio 2.1.2 with the following config at the top of my android section:

    android {
        compileSdkVersion 24
        buildToolsVersion "23.0.3"
    
        defaultConfig {
            applicationId "com.xyz.abc"
            minSdkVersion 14
            targetSdkVersion 24
            //..etc
    
    0 讨论(0)
  • 2020-11-27 12:26

    I had the same problem. I started a new project and it worked, so I just copied the build.gradle file. In my case the only difference was the lack of the compileOptions section. I removed it from my project, synced gradle, re-inserted the compileOptions section and then synced gradle again.

    0 讨论(0)
提交回复
热议问题