也许它可以帮助您解决 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 后,确保执行以下操作:
重新启动系统或运行 source ~/.bash_profile
从您的项目中移除 Android 平台 ionic cordova platform rm android 或 ionic platform rm android
添加Android平台ionic cordova平台添加android
然后ionic cordova run android或ionic run android
说明 2: 要设置您的 ANDROID_HOME 和 JAVA_HOME,请按照以下步骤操作:
- 运行命令打开 ~/.bash_profile
- 将以下内容粘贴到文本编辑器打开的文件中
export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1 导出 PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
- 保存 - “Command S”或“Ctrl S”
- 然后按照上面的“说明 1:”进行操作
注意:确保您拥有 **24.4.1_1SDK**
希望这对您有所帮助。
关于android - 使用 ionic android 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28428347/