【问题标题】:IllegalStateException:buildToolsVersion is not specifiedIllegalStateException:未指定 buildToolsVersion
【发布时间】:2016-07-21 06:40:59
【问题描述】:

我的项目由两个模块组成,一个是应用程序模块,另一个是库模块。在我添加两个 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

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

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

【问题讨论】:

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


    【解决方案1】:

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

    我使用的是 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我们可以看到更多细节。

    【讨论】:

      【解决方案2】:

      在我将版本代码长度从“2017041201”缩短到 8 个字符数之前,我遇到了这个错误:

      android-versionCode="20170412"
      

      【讨论】:

        【解决方案3】:

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

        由于某种原因,我在安装插件时从 Cordova/Ionic 收到此错误。

        当我输入命令时它已修复

        ionic plugin add foo
        

        而不是(前导空格)

         ionic plugin add foo
        

        【讨论】:

          【解决方案4】:

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

          【讨论】:

            【解决方案5】:

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

            repositories {
            
                mavenCentral()
            }
            

            【讨论】:

              【解决方案6】:

              我收到此错误,因为 ANDROID_HOME 设置为 /usr/local/Caskroom/android-platform-tools/latest

              我不知道为什么它被设置为上述值。 但在更正此并将其设置为/Users/<user_name>/Library/Android/sdk/ 后,错误消失了。

              【讨论】:

                【解决方案7】:

                这对我有用

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

                【讨论】:

                  猜你喜欢
                  • 2017-12-07
                  • 2016-09-19
                  • 1970-01-01
                  • 2016-05-03
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2015-02-24
                  • 1970-01-01
                  相关资源
                  最近更新 更多