Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 535
Sauron Avatar asked Jan 01 '15 23:01

Sauron


4 Answers

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:

  • https://www.gradle.org/
  • http://tools.android.com/tech-docs/new-build-system/version-compatibility

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
like image 67
Jared Burrows Avatar answered Oct 23 '22 08:10

Jared Burrows


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.

like image 42
iTapAndroid Avatar answered Oct 23 '22 07:10

iTapAndroid


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'
}
like image 27
Rahul Kumar Avatar answered Oct 23 '22 08:10

Rahul Kumar


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

like image 14
KOTIOS Avatar answered Oct 23 '22 09:10

KOTIOS