47

What should i do to fix this issue? I am getting this error when i ever i run my project in android studio0.9.1

android {compileSdkVersion 17
buildToolsVersion "19.1.0"

defaultConfig {
    applicationId "com.example.nearby"
    minSdkVersion 11
    targetSdkVersion 19
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}}dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:19.0.0'
compile files('libs/google-play-services.jar')}
Youri
  • 613
  • 1
  • 6
  • 12
  • I ran into the same problem. Please check: http://stackoverflow.com/a/32685132/1495235 – Traveller Sep 20 '15 at 23:05
  • I ran into the same problem. Please check [my answer here][1]. [1]: http://stackoverflow.com/a/32685132/1495235 – Traveller Sep 20 '15 at 23:07
  • @Traveller just for future reference, to link in comments, use this syntax: `[text](link)` – Ky - Nov 19 '15 at 20:08
  • I had the same problem and found a solution, [check this answer!](http://stackoverflow.com/a/33904563/3527780) – pmaroco Nov 24 '15 at 22:02
  • [You can try it from stackoverflow.com](http://stackoverflow.com/questions/27735646/android-studio-gradle-dsl-method-not-found-android-error17-0) by Jared Burrows' answer.Hope it helps anyone. – linmufeng Feb 26 '16 at 15:09

5 Answers5

107

I just ran into this same error. Make sure you don't have an android block in the top-level build.gradle for the project, only in the module's build.gradle file.

This happened to me when AndroidStudio tried to import and existing, buildable Eclipse/ADT project–I had to cut and paste the android block from one gradle file to the other. I don't know if this has been fixed in more recent versions of AndroidStudio.

Ionoclast Brigham
  • 1,703
  • 1
  • 12
  • 19
  • 2
    first thing i was working on the low level build.gradle, which is wrong, second, i used this code at the end – Youri Dec 18 '14 at 08:32
  • 7
    (Might be nice to accept this answer, if you feel it is useful.) – Ionoclast Brigham Dec 28 '14 at 21:28
  • @Youri I could use some more details on what you did to fix this. I can't figure it out. – chntgomez Jan 08 '15 at 19:51
  • 1
    I might point out, as an addendum, that this happened to me when AndroidStudio tried to import and existing, buildable Eclipse/ADT project–I had to cut and paste the `android` block from one gradle file to the other. I don't know if this has been fixed in more recent versions of AndroidStudio. – Ionoclast Brigham Jan 27 '15 at 22:37
  • additionally remove any code like: dependencies { } – Kemalettin Erbakırcı Mar 11 '15 at 23:13
  • @KemalettinErbakırcı Have you seen AndroidStudio auto-generating dependencies blocks and that causing errors? Is is this just a common mistake you've seen people make? – Ionoclast Brigham Mar 18 '15 at 18:50
14

I ran into the same problem. My fix was adding "apply plugin: 'android'" before android block... Hope it helps anyone.

fmmarques
  • 301
  • 3
  • 3
5

Inspired by Ionoclast Brigham's answer I've checked both gradle files. I had android() in both of them... but instead of moving android() from the root one to module one I've just added

apply plugin: 'android'

to root one and build works fine.

2

in my case i had to delete these lines from the top-level build.gradle file as it's a bug in the android studio which inserts this

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
}
Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52
0

Solution is found here under runProguard section. In short, it says;

To update your project, edit your build.gradle file as follows:

}
     release {
         runProguard true
         minifyEnabled true
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
     }
Dave Agaba
  • 213
  • 1
  • 4
  • 13