使用Ionic构建Android应用失败

3
也许这可以帮助您解决在Windows系统上使用ionic/cordova构建Android平台时遇到的错误。
在安装了ant/ionic之后:
%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\build-tools

开始一个新项目:ionic start hello blank -> 确定 添加 Android 平台:ionic platform add android -> 确定 构建 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项目(不是ionic),构建成功。
如果我检查c:\android-sdk\build.xml上的问题并添加

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

我看到aapt.exe的路径在android-21上(目标是android-19)。
对我来说,问题在于我有两个Android SDK:android 19和android 21。如果我在Windows上使用CLI,ionic/cordova会默认选择android-21\aapt.exe,而没有android-19\aapt.exe。
我尝试通过用android版本强制路径:%ANDROID_HOME%\build-tools\19.0.0,但没有成功。
为了解决这个问题,我改变了路径,强制aapt可执行文件的路径指向android 19: 文件c:\android-sdk\tools\ant\build.xml:
<aapt executable="C:\android-sdk\build-tools\19.0.0\aapt.exe" ...
</aapt>

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

1个回答

1

指示 1:

在添加ANDROID_HOME后,请确保执行以下步骤:

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

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

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

  4. 然后运行ionic cordova run androidionic run android

指示 2: 要设置ANDROID_HOMEJAVA_HOME,请按以下步骤操作:

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

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

  1. 保存 - "Command S" 或 "Ctrl S"
  2. 然后按照上面的 "指令1:" 进行操作

注意:确保你有 **24.4.1_1 SDK**

希望这可以帮到你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接