12

After changing targetSdkVersion and compileSdkVersion to 22, and changing my buildToolsVersion to 22.0.1, I keep getting the following error:

'buildTypes' cannot be applied to '(groovy.lang.Closure< com.android.build.gradle.internal.dsl.BuildType>)'

I looked at my build.gradle file and tried to look for anything that could be an error:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "********"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 17
        versionName "1.5-beta"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
        freeFlavour {
            applicationId "********"
        }
        paidFlavour {
            applicationId "********"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:7.0.0'
}
Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125

1 Answers1

25

Answer:

For some reason, I found that cutting (Ctrl + X) the buildTypes section and pasting it below the productFlavours section, then moving it back to where it was seemed to solve the issue.

Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125
  • 4
    Damn you are right! It's unbelievable how many bugs google has in all of its products. Actually they are trying to make a developer's experience a living hell -.- – ThanosFisherman May 07 '15 at 00:57
  • Annoyingly enough, this is contrast to what `Gradle` has on their [website](http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard). – craned Aug 24 '15 at 16:32
  • For what it's worth, I also undid the changes, and it seemed to still work so I don't know just what this does. – craned Aug 24 '15 at 16:49
  • Haha SH** Google.. you are right I did CTR+X then CTRL+V solved my problem! – mboy Nov 04 '16 at 07:24
  • a simple solution for this issue - Just invalidate caches and restart from -----> Android studio - File - Invalidate caches and restart – Mani kandan Dec 13 '17 at 07:29