Solving the “gradle DSL method not found: android()” issue in Android Studio

The time when I am writing this blog, I am using Android Studio version 1.0.1. I just migrated one of my eclipse project to android studio. I just smashed next buttons in the “Import Non Android Studio Project” section which it generally asks on the start-up of android studio.

I was having hard time with this error:

gradle DSL method not found: android()

Turned out that, I did not fix my gradle files right. As I did mention in one of my previous blog post, that you need to make two different gradle files. One for the app and other for the module. Some how either we mix them up or do not put proper configuration.

Following are the configuration which got my work going:

1. App configuration:

Put these lines in app gradle configuration. This build.gradle  file is placed in [PROJECT_HOME]/build.gradle.

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

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

allprojects {
 repositories {
 jcenter()
 }
}

2. Module configuration:

Put these lines in module gradle configuration. This  build.gradle is [PROJECT_HOME]/app/build.gradle.

apply plugin: 'com.android.application'

android {
 compileSdkVersion 21
 buildToolsVersion "21.1.2"

 defaultConfig {
 applicationId "com.javatechig.feedreader"
 minSdkVersion 15
 targetSdkVersion 21
 versionCode 1
 versionName "1.0"
 }
 buildTypes {
 release {
 minifyEnabled false
 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
 }
 }
}

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 compile 'com.android.support:appcompat-v7:21.0.3'
 compile 'com.android.support:cardview-v7:+'
}

Hopefully this solves your problems too.