hyeri hyeri - 5 months ago 57
Android Question

Error(19,0) Gradle DSL method not found: android()

I just upgraded android studio and the previously compiled project is now showing errors!


Error(19,0) Gradle DSL method not found: android()


, Here is the build script and app.build.gradle

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}

android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
productFlavors {
}
}

dependencies {
}


and here is the build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.aqsa.personal.newpro"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {

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

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}

Answer

Here is the build script and app.build.gradle

Remove everything after the allprojects closure out of the top-level build.gradle file, leaving you with:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
  }
    allprojects {
      repositories {
    jcenter()
}
}

The android closure, in particular, needs to be in a module that is using one of the Gradle for Android plugins (e.g., com.android.application).