【问题标题】:Ionic: can't build Android appIonic:无法构建 Android 应用程序
【发布时间】:2015-04-03 16:59:07
【问题描述】:

我正在尝试使用 inonic build android 构建 Android 应用,但出现以下错误:

running cordova build android
Running command: "c:\Program Files\nodejs\node.exe" c:\xampp\htdocs\discipulado\
discipulado\hooks\after_prepare\010_add_platform_class.js c:/xampp/htdocs/discip
ulado/discipulado
add to body class: platform-android
Running command: c:\xampp\htdocs\discipulado\discipulado\platforms\android\cordo
va\build.bat
[Error: Please install Android target: "android-21".

Hint: Open the SDK manager by running: C:\Users\Thiago\AppData\Local\Android\sdk
\tools\android.BAT
You will require:
1. "SDK Platform" for android-21
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools" (latest)]
ERROR building one of the platforms: Error: c:\xampp\htdocs\discipulado\discipul
ado\platforms\android\cordova\build.bat: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: c:\xampp\htdocs\discipulado\discipulado\platforms\android\cordova\build.b
at: Command failed with exit code 2
    at ChildProcess.whenDone (c:\Users\Thiago\AppData\Roaming\npm\node_modules\c
ordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

我已经安装了 Apache Ant,但错误仍然存​​在。我使用ionic platform remove android 删除了Android 平台并添加了ionic platform add android,但没有成功。

有什么想法吗?

更新 我已经安装了 Android Studio 和 Android SDK 工具。

【问题讨论】:

    标签: android cordova ant ionic


    【解决方案1】:

    如错误提示,您的系统需要安装“android-21”,即Android 5.0 Lollipop

    【讨论】:

    • 我检查了 Android SDK 管理器并安装了以下项目 Android 5.0.1:SDK 平台、Google API、Android SDK 源。
    • 漏掉的是,在环境变量PATH中,添加这两项 1. path-to-android-sdk-***/tools 2. path-to-android-sdk-* **/平台工具。如果它有效,请更新我。
    • 不确定发生了什么。我刚刚重写了Path 中的ant/bin 文件夹,并且成功了。