简体   繁体   中英

Error:Cause: buildToolsVersion is not specified

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.

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.

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'
        }

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!!!

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'

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.

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".

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.

Android Project > setting.gradle

include ':app' , ':xxx'

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

include ':app'

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

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

我有同样的错误,我使用cordova并通过删除空格字符来解决

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

尝试使缓存无效/重新启动,它在更新文件->使缓存/重新启动后修复了这个问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM