17

Getting a bug, when I try to compile my project in studio , i have search quite a bit with no real solution to it

Error:(17, 0) Could not find method android() for arguments [build_a7zf1o8ge4ow4uolz6kqzw5ov$_run_closure2@19201053] on root project 'booksStudioDir' of type org.gradle.api.Project.

This is a sample of my build/gradle file

buildscript {
repositories {
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
  }
 }
  apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


android {
compileSdkVersion 21
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.peade.time"
    minSdkVersion 10
    targetSdkVersion 13
}
signingConfigs {
    release {
        storeFile file("/home/bestman/Desktop/mkey/key")
        storePassword "androidkeys"
        keyAlias "peade"
        keyPassword "yes1234"
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.txt'
        signingConfig signingConfigs.release
     }
  }
}
  repositories {
    maven { url 'https://maven.fabric.io/public' }
    mavenCentral()
 }
dependencies {
   compile 'com.edmodo:cropper:1.0.1'
   compile 'com.android.support:support-v4:21.0.3'
   compile 'com.itextpdf:itextpdf:5.5.6'
   //    compile files('libs/commons-lang3-3.3.2.jar')
   compile files('libs/dropbox-android-sdk-1.6.1.jar')
   //    compile files('libs/httpmime-4.0.3.jar')
   compile files('libs/json_simple-1.1.jar')
   compile files('libs/picasso-2.5.2.jar')
   compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
    transitive = true;
   }
   compile project(':owncloud')
 }
Omega
  • 289
  • 1
  • 4
  • 14
  • possibly duplicated http://stackoverflow.com/questions/37250493/could-not-find-method-android-for-arguments – nshmura Oct 13 '16 at 11:48
  • @nshmura I didnt find my answer with that – Omega Oct 13 '16 at 12:14
  • Did you define an android block in your top-level build.gradle? – nshmura Oct 13 '16 at 12:23
  • @nshmura not sure of what you mean, but how can I do that? This particular project was compiling before, but since I just downloaded and install this new android studio, I have been having this issue with this project. – Omega Oct 13 '16 at 12:33

3 Answers3

22

There are two build.gradle files. One is in the top-level holder, and the other is in module holder.

Below is an example.

Top-level build.gradle:
https://github.com/nickbutcher/plaid/blob/master/build.gradle

module's build.gradle:
https://github.com/nickbutcher/plaid/blob/master/app/build.gradle

The android block should be in module's build.gradle. I guess you must have defined the android block in top-level build.gradle which is causing the error.

Swati Bhartiya
  • 101
  • 1
  • 8
nshmura
  • 5,940
  • 3
  • 27
  • 46
  • 1
    I have same problem, android block is in module's build.gradle but still have same problem. actually last week everything was ok but suddenly today I got this problem – MehrAmoon Nov 07 '19 at 08:02
  • I just added " apply plugin: 'com.google.gms.google-services' " before android block an everything ok now – MehrAmoon Nov 07 '19 at 08:25
4

I had same problem if your android block is in module's build.gradle and use google services, just add these 2 lines before android block:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
MehrAmoon
  • 187
  • 1
  • 5
0

Invalidate Cache and restart

Go to : File/Invalidate Cache/Click on Invalidate and Restart This should solve your problem for you.