61

I create a simple project and then I right-click on the project and then I use the make mudole app option. Now I have two build.gradle folders: 1- build.gradle:project My Application. 2- build.gradle: Mudole app. the first build.gradle is as follows:

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

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

allprojects {
    repositories {
        jcenter()
    }
}

And the second Build.gradle folder is as follows:

 apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.exam.exam.myapplication"
        minSdkVersion 7
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

And now I click on the run option to create aar file from this project But I get the following error:

Error:Cause: buildToolsVersion is not specified.
developer
  • 613
  • 1
  • 5
  • 4

12 Answers12

82

I had the same issue. What I was doing wrong was the placing of apply plugin statement in the root gradle of the project. When I placed it in the app gradle then the issue got resolved.

What I would suggest is to check if you are placing some statement in the root gradle that you should be placing in the app gradle.

arghtype
  • 4,376
  • 11
  • 45
  • 60
Akshay
  • 1,020
  • 6
  • 10
13

Add buildToolsVersion to your build.gradle file this will solve your problem.

buildToolsVersion "27.0.1"

Gradle file code

 android{
          compileSdkVersion 27
          buildToolsVersion "27.0.1"
          useLibrary 'org.apache.http.legacy'
        }
Sagar
  • 5,273
  • 4
  • 37
  • 50
8

Add buildToolsVersion property to your local build.gradle file.

android {
    compileSdkVersion 27
    buildToolsVersion "26.0.1"

    defaultConfig {
        targetSdkVersion 27
    }
}

As per your requirements!! Then Try to build -> you will get build failure and this message :

Failed to find Build Tools revision 26.0.1

Install Build Tools 26.0.1 and sync project

Then Click to Install build tools and your project is configured and you are good to go!!!

Community
  • 1
  • 1
DesignIsLife
  • 510
  • 5
  • 11
  • this is newer: `buildToolsVersion "28.0.2"` – Eugene Gr. Philippov Jan 26 '19 at 03:49
  • At this point, it will even request that you remove the build tools version within your build gradle file after you introduce it. But, including it in the first place when migrating from an older build target at least gets you past this error. And then you can remove it after. – Jay Snayder Feb 14 '19 at 16:22
7

in file... build.gradle(Project: XXX):

repositories{
     //put pluging repository here
     //e.g.:
     mavenCentral()
}
dependencies{
     //classpath to plugin here
     classpath 'com.XXXX.xXXxxXX.XXXX' 
}

in file.... build.gradle(Module: app)

//add on top:
apply plugin: 'com.YOUR.PLUGIN.XXX'
RickPat
  • 487
  • 6
  • 6
4

The issue for me was that andorid-versionCode can only be integer value. in build.xml:

eg:android-versionCode="1"

It cannot be "1.1" etc... The error code is not helpful at all.

1

Not really sure what the underlying problem was, but I found the solution in a concurrent problem that was occurring: https://stackoverflow.com/a/32490472/1544046

Essentially, I had to change my gradle target to use the wrapper and not a defined path. I've had it set to the Gradle Wrapper in the past, but it seems to revert from time to time without notice. Once I switched back and recompiled it worked fine.

In the project's settings: Build, Execution, Deployment->Build Tools->Gradle and select "Use default gradle wrapper".

Community
  • 1
  • 1
JCricket
  • 1,318
  • 2
  • 17
  • 34
1

Might be helpful for someone: in my case long time ago I had added keystore properties in build.gradle file for Android:

def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

and after some period of time I pulled repo and forgot to add this file ("keystore.properties").

Gradle for some reason (!) gave me the same error (buildToolsVersion was defined a bit below in build.gradle file). The workaround was just to add missing "keystore.properties" file.

Mitrakov Artem
  • 1,355
  • 2
  • 14
  • 22
0

Android Project > setting.gradle

include ':app' , ':xxx'

I imported one of module and this coused this error. I remove it is fixed.

include ':app'
Huseyin
  • 567
  • 6
  • 17
  • But isn't " include ':app' , ':xxx' " how you integrate the specified module with the name "xxx" ? So basically you aren't actually including the module? Please correct me if I'm wrong. – flumingo Nov 13 '16 at 15:58
  • I just give example :) It wasn't :xxx.. I added one of module manually and mentioned line added by itself.. – Huseyin Nov 13 '16 at 19:57
0

Check if android studio version in build.gradle is same as the one you are running.

buildscript {

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


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

In my case, I opened/imported the project created on android studio 2.3.3 in android studio 3 and i was able to get rid of this issue after updating the build.gradle with 3.0.0

0

for me it was an additional classpath line for example :

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

so i was deleting the first

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'

and the issue solved

AflamZone
  • 81
  • 2
  • 3
0

I had same error, I using cordova and resolve by removing the space character

id="com.xx.yy " => to id="com.xx.yy"

Ferhat KOÇER
  • 3,890
  • 1
  • 26
  • 26
-5

Try to invalidate caches / restart , it fixed this like this after updated File-> Invalidate caches/restart

Kirtan
  • 1,782
  • 1
  • 13
  • 35