【问题标题】:Cordova: buildToolsVersion is not specified (MacOS)Cordova:未指定 buildToolsVersion (MacOS)
【发布时间】:2017-12-07 01:55:26
【问题描述】:

我在运行cordova build android --release时遇到错误

Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.IllegalStateException: buildToolsVersion is not specified.

好像没有指定 buildToolsVersion。

这是 Cordova 使用的 Android_Home。

ANDROID_HOME=/usr/local/Caskroom/android-platform-tools/latest

基本上我正在尝试用下面的方式更改此路径,但它不会更改 Cordova 构建中的路径。

我正在使用以下命令来更改路径。

export ANDROID_HOME=/Users/admin/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH

source .bash_profile
echo $ANDROID_HOME

但它不会改变 Cordova 中的路径。

编辑:我还尝试在 Cordova 中删除和添加 android 平台。

编辑 2: 如果我使用相同的终端,则 android_home 的路径会更改。好像 bashrc 没有更新。

但是现在我遇到了不同的错误并且构建失败了。

platforms/android/src/org/apache/cordova/file/FileUtils.java:15: error: <identifier> expected

我已经安装了 sdk build tool 版本 19.1.0、23.0.1 和 26.0,但仍然出现错误。

编辑 3build.gradle

apply plugin: 'com.android.application'

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    // Switch the Android Gradle plugin version requirement depending on the
    // installed version of Gradle. This dependency is documented at
    // http://tools.android.com/tech-docs/new-build-system/version-compatibility
    // and https://issues.apache.org/jira/browse/CB-8143
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
    repositories {
        mavenCentral();
        jcenter()
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.14.1'
}

// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
ext {
    apply from: 'CordovaLib/cordova.gradle'
    // The value for android.compileSdkVersion.
    if (!project.hasProperty('cdvCompileSdkVersion')) {
        cdvCompileSdkVersion = null;
    }

编辑 4:现在我的 Android 和 Java 路径如下。

ANDROID_HOME=/Users/admin/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home

当我运行 cordova build android 时,我遇到了错误。

com.sun.tools.javac.parser.JavacParser.classOrInterfaceOrEnumDeclaration(JavacParser.java:3226)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

【问题讨论】:

    标签: android cordova


    【解决方案1】:

    查看Cordova Android GitHub reposearching it for buildToolsVersion,您会在build.gradle 中看到Android buildToolsVersion 当前设置为23.0.1

    单击上面的搜索链接,并尝试安装为文件build.gradle 显示的Android Build Tools 版本。

    【讨论】:

    • 感谢您的回答,但 2 天前配置相同,它工作正常。
    • 我正在添加 build.gradle 的内容
    • 我已经安装了 23.0.1 sdk 工具,但仍然失败并出现同样的错误。
    • 我也通过 Brew 安装了 Android SDK。我的ANDROID_HOME 与您上面的不同。在我的.bash_profile 我有export ANDROID_HOME=/usr/local/opt/android-sdk
    • 我需要通过 brew 安装它吗?
    猜你喜欢
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 2016-09-22
    • 2016-10-01
    • 1970-01-01
    • 2019-07-07
    • 2021-06-07
    相关资源
    最近更新 更多