android - 非法状态异常 :buildToolsVersion is not specified

标签 android android-gradle-plugin 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

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

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

最佳答案

OK,这个问题找了好久,终于搞定了。

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

关于android - 非法状态异常 :buildToolsVersion is not specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38496747/

相关文章:

android - 与 Android 和 iOS 进行 Azure 服务总线消息传递

Android MediaStore 获取不同的音乐文件文件夹

android - 使用 FCM 进行 ANR 并使用 applicationIdSuffix 构建变体

java - 找不到参数的 Compile() 方法 [com.android.support :support

android - native 项目无法生成错误 : Error configuring

java - 我的 Java 项目的 gradle 构建出错

android - `@Singleton` 与 `@InstallIn(SingletonComponent::class)`

java - 在 Android 中调用 REST Web 服务并在字符串数据中获取 null

android - 在前缀为 : mips64el-linux-android 的 ABI 的 NDK 工具链文件夹中找不到工具链

gradle - 配置 'compile'已过时。替换为实现后出现错误