IllegalStateException:未指定buildToolsVersion

时间:2016-07-21 06:41:00

标签: android android-gradle build.gradle gradle-plugin

我的项目由两个模块组成,一个是应用程序模块,另一个是库模块。我的构建过程正常,直到我添加了两个gradle插件:

这是根build.gradle

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

        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'

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

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是一个库模块build.gradle

apply plugin: 'com.android.library'

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

android {

    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    resourcePrefix "looping_banner_res_"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:24.1.0'
}

我不认为构建文件有问题,但是当我运行gradle clean时出错:

Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.IllegalStateException: buildToolsVersion is not specified.
    at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
    at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:606)
    at com.android.build.gradle.BasePlugin$10$1.call(BasePlugin.java:572)
    at com.android.build.gradle.BasePlugin$10$1.call(BasePlugin.java:569)
    at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:55)
    at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:47)
    at com.android.build.gradle.BasePlugin$10.execute(BasePlugin.java:568)
    at com.android.build.gradle.BasePlugin$10.execute(BasePlugin.java:565)

* Where:
Build file '/home/lic/code/private/github/looping-banner/banner/build.gradle' line: 3

为什么会出现这个问题以及如何解决这个问题?

我已经搜索了一些答案,但对我不起作用,我导入的两个插件中有什么问题吗?

7 个答案:

答案 0 :(得分:2)

好的,经过大量关于这个问题的搜索,我终于解决了。

我使用Gradle 2.14,所以我需要更改

classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'

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

存在很多差异,here我们可以看到更多细节。

答案 1 :(得分:1)

我有错误,直到我缩短版本代码长度为" 2017041201"到8个字符数:

android-versionCode="20170412"

答案 2 :(得分:1)

这个问题很老,但我发现它是因为我遇到了这个问题 -

出于某种原因,我在安装插件时遇到了来自Cordova / Ionic的错误。

我输入命令

时修复了
ionic plugin add foo

代替(领先空间)

 ionic plugin add foo

答案 3 :(得分:1)

我有同样的问题,问题是在android-versionCode中有点,
如:android-versionCode="10001.1"

答案 4 :(得分:0)

您在存储库依赖项中缺少mavencentral()。也许这会导致问题

repositories {

    mavenCentral()
}

答案 5 :(得分:0)

我得到此错误因为ANDROID_HOME设置为"id" "user_name" "enabled" "first_name" "last_name" "email" "user_password" "user_password_salt" "last_login_time" "creation_time" "last_edit_time" "valid_till" "role_id" "role_name" "role_description" "1" "admin" "True" "Admin" "User" "adminuser@gmail.com" "SEli9hsMTTxGgjrlCz48+5w1CaMnUe/8xJJ0enOZ2ag=" "mBPa0wNPjvnGK3gzDMOHOg==" "28-05-2017" "28-05-2017" "28-05-2017" "31-05-2018" "1" "ADMIN" "Administrator user"

我不知道为什么它会设置为上述值。 但在纠正此问题并将其设置为/usr/local/Caskroom/android-platform-tools/latest后,错误就会消失。

答案 6 :(得分:0)

这对我有用

Remove android / Add android:
cordova platform rm android
cordova platform add android