android - 使用 ionic android 构建失败

标签 android cordova ant ionic-framework

也许它可以帮助您解决 ionic/cordova 错误与 android 平台在 windows 上的构建错误

安装 ant/ionic 之后:

%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\build-tools

开始一个新项目:ionic start hello blank ->ok ionic 平台添加 android -> 确定 ionic 构建 android - 错误:

BUILD FAILED
C:\SDK\android-sdk\tools\ant\build.xml:954: The following error occurred while executing this line:
C:\SDK\android-sdk\tools\ant\build.xml:971: null returned: -1073741819

Total time: 2 seconds

D:\PROD\myapp\platforms\android\cordova\node_modules\q\q.js:126
                throw e;
                      ^
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,D:\PROD\myapp\platforms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
ERROR building one of the platforms: Error: D:\PROD\myapp\platforms\android\cordova\build.bat: Command failed with exit code 8
You may not have the required environment or OS to build this project

路径没问题,如果我开始一个新的 cordova projet(非 ionic )构建是成功的。

如果我检查 c:\android-sdk\build.xml 上的问题并添加

<echo>aapt:  ${aapt}</echo>

我可以看到 aapt.exe 路径在 android-21 上(目标是 android-19)

For me, problem is I have two android sdk : android 19 and android 21. If I use CLI on windows, ionic/cordova choose android-21\aapt.exe by default and no android-19\aapt.exe

I tried to force Path with android version : %ANDROID_HOME%\build-tools\19.0.0 with no success.

To resolve this problem I changed paths to force on aapt executable path to point on android 19: File c:\android-sdk\tools\ant\build.xml :

<aapt executable="C:\android-sdk\build-tools\19.0.0\aapt.exe" ...
</aapt>

这不是最好的方法,但我还没有找到其他方法。

最佳答案

说明1:

添加您的 ANDROID_HOME 后,确保执行以下操作:

  1. 重新启动系统或运行 source ~/.bash_profile

  2. 从您的项目中移除 Android 平台 ionic cordova platform rm androidionic platform rm android

  3. 添加Android平台ionic cordova平台添加android

  4. 然后ionic cordova run androidionic run android

说明 2: 要设置您的 ANDROID_HOMEJAVA_HOME,请按照以下步骤操作:

  1. 运行命令打开 ~/.bash_profile
  2. 将以下内容粘贴到文本编辑器打开的文件中

export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1 导出 PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

  1. 保存 - “Command S”或“Ctrl S
  2. 然后按照上面的“说明 1:”进行操作

注意:确保您拥有 **24.4.1_1SDK**

希望这对您有所帮助。

关于android - 使用 ionic android 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28428347/

相关文章:

java - 是否可以制作一个在拍照时录制音频的 Android 应用程序?

javascript - 上传前在phonegap中预览图像

cordova - PhoneGap 应用程序服务器端包含 (SSI)

android - Cordova/PhoneGap - 增加守护进程 OSX 的堆大小

java - 从 Ant/命令行关闭 HSQLDB

Android RecyclerView 与 CardView : Margins between cards

android - Videoview暂停和恢复

android - C2DM 推送通知 401 未授权错误的原因是什么?

java - 使用 ant 在 Web 应用程序中检测 lib jar

java - 使用 ANT 构建 Android 项目 (Zxing)