Marco Delavegua
Marco Delavegua

Reputation: 61

Build failed with ionic android

Maybe it can help you on build error with ionic/cordova error with android platform on windows

After install ant/ionic with :

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

start a new projet : ionic start hello blank ->ok ionic platform add android -> ok ionic build android - Error:

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

Paths are OK and if I start a new cordova projet (not ionic) build is a success.

If I check problem on c:\android-sdk\build.xml and I add

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

I can see aapt.exe path is on android-21 (target is 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>

This is not the best way, but I have not found another.

Upvotes: 3

Views: 2072

Answers (1)

Victor Ejiogu
Victor Ejiogu

Reputation: 1384

Instruction 1:

After adding your ANDROID_HOME, make sure you do the below:

  1. Restart your System or run source ~/.bash_profile

  2. Remove Android platform from your project ionic cordova platform rm android or ionic platform rm android

  3. Add Android platform ionic cordova platform add android

  4. Then ionic cordova run android or ionic run android

Instruction 2: To set your ANDROID_HOME and JAVA_HOME, follow the below steps:

  1. Run command open ~/.bash_profile
  2. Paste the below in the file that opens on your Text editor

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

  1. Save - "Command S" or "Ctrl S"
  2. Then Follow the "Instruction 1:" above

NOTE: Make sure you have **24.4.1_1 SDK**

Hope this helps.

Upvotes: 1

Related Questions