请安装 Android target: "android-21" 但它安装了吗?

Please install Android target: "android-21" but it is installed?

我的问题

我一直在使用 visual studio 中的 Tools for Apache Cordova 模板来构建一个应用程序,它已经为我工作了大约两个月,一点问题都没有,但是昨天我构建了它大约 6 次之后突然它刚刚停止工作。

在 VS 中,您会遇到一些非常糟糕的构建错误,这些错误并没有告诉您很多关于问题的信息,例如:

Severity Code Description Project File Line Source Error C:\Konstruktion\MyFirstApp\MyFirstApp\MyFirstApp\platforms\android\cordova\build.bat: Command failed with exit code 1 MyFirstApp C:\Konstruktion\MyFirstApp\MyFirstApp\MyFirstApp\ERROR building one of the platforms 1 Build

Severity Code Description Project File Line Source Error C:\Konstruktion\MyFirstApp\MyFirstApp\MyFirstApp\platforms\android\cordova\build.bat: Command failed with exit code 1 MyFirstApp C:\Konstruktion\MyFirstApp\MyFirstApp\MyFirstApp\MDAVSCLI 1 Build

所以我确实尝试在没有 visual studio 的帮助下仅使用 CMD 命令来构建它,这是我随后得到的错误:

[Error: Please install Android target: "android-21"]
Hint: Open the SDK manager by running C:\Users\username\AppData\Local\Anndroid\sdk\tools\android.BAT
You will require:
1. "SDK Platfrom" for android-21
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools (latest)]
Error: cmd: Command failed with exit code 2
at ChildProsses.whenDone (C:\Users\myUsername\AppData\Roming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:134:23)
at ChildProcess.emit (events.js:110:17)
at mybyClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

(这是手写的感觉,如果你知道我可以更新问题,我不知道如何从 cmd 复制到整个输出)。

到目前为止我已经尝试过的事情

  1. 通过 SDK 管理器重新安装要求的工具和 sdk 平台
  2. 重新安装整个sdk
  3. this Stack Overflow question

我今天要尝试什么?

  1. 读者可以想出的绝妙解决方案!
  2. 在另一台计算机上安装所有内容并在那里尝试
  3. 在 windows-10 上试试(这样会有帮助)

图片

我找到问题出现的原因了。这是一个只影响用户如何使用 Cordova 工具的问题 Visual Studio! (我认为)。

如果您开始构建然后在选择了设备或模拟器的情况下取消它,它会损坏调试文件夹中的一些文件:

C:\Konstruktion\myApp\myApp\myApp\bin\Android\Debug

或者你放的地方。

如果您不知道它在哪里,只需在解决方案资源管理器中右键单击项目名称,然后单击 "Open path in File Explorer"

导航到调试文件夹并删除它的内容,重新构建它应该会再次工作。

bin\Android\Debug