Error:(1, 0) Gradle DSL method not found: 'and

2019-02-02 02:25发布

问题:

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')}

回答1:

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.



回答2:

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



回答3:

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.



回答4:

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'
}


回答5:

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'
     }