科尔多瓦在运行项目时失败 - 未找到已安装的构建工具 - 未指定 compileSdkVersion

Posted

技术标签:

【中文标题】科尔多瓦在运行项目时失败 - 未找到已安装的构建工具 - 未指定 compileSdkVersion【英文标题】:cordova fails on running a project - No installed build tools found - compileSdkVersion is not specified 【发布时间】:2021-07-13 02:22:18 【问题描述】:

我创建了一个新的 cordova 项目,但它没有启动。 我按照下面描述的步骤操作:

创建项目:

PS D:\MyProjects> npm install -g cordova
PS D:\MyProjects> cordova create mycordova

添加平台:

PS D:\MyProjects> cd mycordova
PS D:\MyProjects\mycordova> cordova platform add browser
PS D:\MyProjects\mycordova> cordova platform add android

设置环境:

PS D:\MyProjects\mycordova> $env:JAVA_HOME="C:\Program Files\Java\jdk8"
PS D:\MyProjects\mycordova> $env:ANDROID_SDK_ROOT="C:\Program Files\Android\Android Studio"
PS D:\MyProjects\mycordova> $env:GRADLE="C:\Gradle\gradle-7.0"
PS D:\MyProjects\mycordova> $env:SDKTOOLS="C:\Users\robin\AppData\Local\Android\Sdk\tools"
PS D:\MyProjects\mycordova> $env:PLATFORMTOOLS="C:\Users\robin\AppData\Local\Android\Sdk\platform-tools"
PS D:\MyProjects\mycordova> set-item -path env:path -value ($env:JAVA_HOME + "\bin;" + $env:ANDROID_SDK_ROOT + "\bin;" + $env:GRADLE + "\bin;" + $env:SDKTOOLS + ";" + $env:SDKTOOLS + "\bin;" + $env:PLATFORMTOOLS + ";" + $env:path)

验证先决条件:

PS D:\MyProjects\mycordova> cordova requirements

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-30,android-29
Gradle: installed C:\Gradle\gradle-7.0\bin\gradle.BAT

Requirements check results for browser:

运行项目和结果:

PS D:\MyProjects\mycordova> cordova run android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Program Files\Android\Android Studio (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Using Android SDK: C:\Program Files\Android\Android Studio
Subproject Path: CordovaLib
Subproject Path: app

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Script 'D:\MyProjects\mycordova\platforms\android\CordovaLib\cordova.gradle' line: 64

* What went wrong:
A problem occurred evaluating project ':app'.
> No installed build tools found. Install the Android build tools version 19.1.0 or higher.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
Command failed with exit code 1: D:\MyProjects\mycordova\platforms\android\gradlew cdvBuildDebug -b D:\MyProjects\mycordova\platforms\android\build.gradle

NPM 版本是 6.14.2NODE 版本是 14.16.1。在 Windows 10 上。

您能帮我找出项目无法启动的原因吗?

【问题讨论】:

【参考方案1】:

找到一个解决方案改变

$env:ANDROID_SDK_ROOT="C:\Program Files\Android\Android Studio"

$env:ANDROID_SDK_ROOT="C:\Users\robin\AppData\Local\Android\Sdk"

添加

$env:BUILDTOOLS="C:\Users\robin\AppData\Local\Android\Sdk\build-tools"

变化自

set-item -path env:path -value ($env:JAVA_HOME + "\bin;" + $env:ANDROID_SDK_ROOT + "\bin;" + $env:GRADLE + "\bin;" + $env:SDKTOOLS + ";" + $env:SDKTOOLS + "\bin;" + $env:PLATFORMTOOLS + ";" + $env:path)

set-item -path env:path -value ($env:JAVA_HOME + "\bin;" + $env:GRADLE + "\bin;" + $env:SDKTOOLS + ";" + $env:SDKTOOLS + "\bin;" + $env:PLATFORMTOOLS + ";" + $env:BUILDTOOLS + ";" + $env:PATH)

【讨论】:

以上是关于科尔多瓦在运行项目时失败 - 未找到已安装的构建工具 - 未指定 compileSdkVersion的主要内容,如果未能解决你的问题,请参考以下文章

离子构建Android |错误:未找到已安装的构建工具。请安装 Android 构建工具

科尔多瓦要求Android目标:未安装

等级:未安装(符合科尔多瓦规定)

科尔多瓦要求 android 目标未安装 cmd:命令失败,退出代码 1 错误输出:

未找到此类模块“GoogleMaps”,但已安装

在 Visual Studio 2019 中编译默认 Angular 项目时未找到(但已安装)node.js