82

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
Abhinav singh
  • 1,448
  • 1
  • 14
  • 31
Sauron
  • 6,399
  • 14
  • 71
  • 136

13 Answers13

56

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
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • First off thanks for the extra effort!! But when I downloaded the project and imported, there was only one build.gradle file. How did you get two, the app and the project? – Sauron Jan 02 '15 at 00:24
  • I downloaded the zip and went through the files via command line. Also, there are usually a top build.gradle and a project build.gradle. When you import your project into Intellij/Android Studio, selected the top build.gradle. There is a top build.gradle and another in the app folder. – Jared Burrows Jan 02 '15 at 00:26
  • @Sauron Does everything work for you? You need to use my updated build.gradles in order for it to run. Also, let me know if you need more help! – Jared Burrows Jan 02 '15 at 00:30
  • @JaredBurrows Can you help with http://stackoverflow.com/questions/30958596/how-to-resolve-low-sdk-build-tools-error as well? It's a similar question to this. I'am having a difficult time with upgrading the Gradle. – committedandroider Jun 20 '15 at 22:43
  • @committedandroider Upgrade your SDK: `Error:The SDK Build Tools revision (19.0.3) is too low for project` – Jared Burrows Jun 21 '15 at 01:35
  • @JaredBurrows I did do that. I installed both Build-tools v 19.1 and Build-tools v 21.1.2 – committedandroider Jun 21 '15 at 01:38
  • It is hard to tell. The libgdx project is auto generated and there maybe another `build.gradle` else where. Is you project on github? – Jared Burrows Jun 21 '15 at 01:41
  • 1
    Just wanted to add a comment that this also works for anyone trying to set up the Parse.com Android QuickStart blank new project which has the same issue if you download and install :) – Max Mar 30 '16 at 22:58
46

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.

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
iTapAndroid
  • 1,875
  • 1
  • 15
  • 12
27

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'
}
Rahul Kumar
  • 469
  • 5
  • 10
14

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

KOTIOS
  • 11,177
  • 3
  • 39
  • 66
10

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.

Geraldo Neto
  • 3,670
  • 1
  • 30
  • 33
Shumoapp
  • 1,489
  • 16
  • 15
1

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.

Traveller
  • 50
  • 4
1

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

Bhushan Shirsath
  • 258
  • 3
  • 12
1

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 !

Raúl EL
  • 1,206
  • 11
  • 6
  • IMHO, Traveller's earlier answer suggesting the creation of a new project to find out what settings to use, is a) easier to do, b) will continue working, in future versions of Android, when the "best" settings to use may have changed. – ToolmakerSteve Sep 19 '16 at 11:29
0

Just delete these lines from the root build.gradle

android {
compileSdkVersion 19
buildToolsVersion '19.1' }

Now trying and compile again. It should work.

k9x
  • 81
  • 5
0

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
}
mesutpiskin
  • 1,771
  • 2
  • 26
  • 30
0

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.

martin36
  • 2,253
  • 4
  • 18
  • 27
0

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

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

it worked。

Ahmad Arif
  • 53
  • 1
  • 8
Andy
  • 9
  • 1
0

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.