Android Studio Gradle DSL method not found: 'android()' -- Error(17,0)

I am attempting to run my project in Android Studio but the error appears below:

enter image description here

I have followed many sources just to get this to run and have wound up here, but do not know what else to do.

How can I configure this project to run?

build.gradle:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}


allprojects {
repositories {
mavenCentral()
}
}


android {
compileSdkVersion 19
buildToolsVersion "19.1"
}

settings.gradle:

include ':app'

local.properties:

sdk.dir=C\:\\Users\\KJA\\AppData\\Local\\Android\\sdk

gradle.propertes:

# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.


# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html


# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8


# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
149574 次浏览

I went ahead and downloaded the project from the link you provided: http://javapapers.com/android/android-chat-bubble/

Since this is an old tutorial, you simply need to upgrade the software, gradle, the android build tools and plugin.

Make sure you have the latest Gradle and Android Studio:

build.gradle:

buildscript {
repositories {
jcenter()
}


dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}


allprojects {
repositories {
jcenter()
}
}

app/build.gradle:

apply plugin: 'com.android.application'


android {
compileSdkVersion 23
buildToolsVersion '23.0.3'


defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName '1.0'
}
}


dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
}

Then run gradle:

gradle installDebug

In your top level build.gradle you seem to have the code

android {
compileSdkVersion 19
buildToolsVersion "19.1"
}

You can't have this code at the top level build.gradle because the android build plugin isn't loaded just yet. You can define the compile version and build tools version in the app level build.gradle.

I have tried to manage this issue via below steps :

Delete android { ... } block in top level root gradle file

Look into

 compileSdkVersion 22
buildToolsVersion "22.0.0"

lines of code in app/gradle file here only one of the version persent in below dropdown should be present else it would give provide option to downloaad the same.

enter image description here

Correcting gradle settings is quite difficult. If you don't know much about Gradle it requires you to learn alot. Instead you can do the following:

1) Start a new project in a new folder. Choose the same settings with your project with gradle problem but keep it simple: Choose an empty main activity. 2) Delete all the files in ...\NewProjectName\app\src\main folder 3) Copy all the files in ...\ProjectWithGradleProblem\app\src\main folder to ...\NewProjectName\app\src\main folder. 4) If you are using the Test project (\ProjectWithGradleProblem\app\src\AndroidTest) you can do the same for that too.

this method works fine if your Gradle installation is healthy. If you just installed Android studio and did not modify it, the Gradle installation should be fine.

I got this same error when I was trying to import an Eclipse NDK project into Android Studio. It turns out, for NDK support in Android Studio, you need to use a new gradle and android plugin (and gradle version 2.5+ for that matter). This plugin, requires changes in the module's build.gradle file. Specifically the "android{...}" object should be inside "model{...}" object like this:

apply plugin: 'com.android.model.application'
model {
android {
....
}
}

So if you have updated your gradle configuration to use the new gradle plugin, and the new android plugin, but didn't change the module's build.gradle syntax, you could get "Gradle DSL method not found: 'android()'" error.

I prepared a patch file here that has some further explanations in the comments: https://gist.github.com/shumoapp/91d815de6e01f5921d1f These are the changes I had to do after importing the native-audio ndk project into Android Studio.

Just delete these lines from the root build.gradle

android {
compileSdkVersion 19
buildToolsVersion '19.1' }

Now trying and compile again. It should work.

Actually i tried many combinations nothing worked

but when i modified my application gradle file with following

 buildTypes {
release {
minifyEnabled false
}
}

By removing the Line

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

it worked Normally :)) cheers

For some unknown reason, Android Studio incorrectly adds the android() method in the top-level build.gradle file.

Just delete the method and it works for me.

android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
}

Change to root build.gradle file

to

// Top-level build file where you can add configuration options common to all sub-projects/modules.


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


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}


allprojects {
repositories {
jcenter()
}
}


task clean(type: Delete) {
delete rootProject.buildDir
}

What worked for me was to import the project with "File -> New -> Project from Version Control" then choose your online source (GitHub for example). This way all the .gradle files were created in the import.

I also meet that problems,and just delete bottom code:

DELETE THESE LINES:
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
}

it worked。

Another solution if you have installed android-studio-bundle-143.2915827-windows and gradle2.14

You can verify in C:\Program Files\Android\Android Studio\gradle if you have gradle-2.14.

Then you must go to C:\Users\\AndroidStudioProjects\android_app\

And in this build.gradle you put this code:

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

Then, go to C:\Users\Raul\AndroidStudioProjects\android_app\Desnutricion_infantil\app

And in this build.gradle you put:

apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24.0.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
}

You must check your sdk version and the buildTools. compileSdkVersion 23 buildToolsVersion '24.0.0'

Save all changes and restart AndroidStudio and all should be fine !

This error has occurred when i was importing a project from Github. This happens as the project was of older version. Just try to delete these methods below from your root gradle.

android { compileSdkVersion 19 buildToolsVersion "19.1" }

then try again.

I hope it works.