Android Build Failed

Depends on your platform, but when I had this issue for just plain “ionic platform build” (on Windows machine), I just had to run:
npm update -g ionic cordova (and bower, since I am using it as well)
After I ran this command, I simply ran:
ionic platform rm android
ionic platform add android
ionic build android

worked like a charm! You may need to run CMD prompt as administrator if you dont have permissions.

Hi newkidd,

thanks for your insight, but unfortunately after I try your step the same error still occur.
This is my ionic information

Cordova CLI: 5.3.1
Ionic Version: 1.1.0
Ionic CLI Version: 1.6.4
Ionic App Lib Version: 0.3.8
ios-deploy version: Not installed
ios-sim version: 2.0.1
OS: Mac OS X Lion
Node Version: v0.12.7
Xcode version: Xcode 4.6.3 Build version 4H1503

I’m running on mac os x Lion (10.7.5). I have no problem when running ionic build ios command.
This is the detail message:

Running command: /Users/Arno/conference/hooks/after_prepare/010_add_platform_class.js /Users/Arno/conference
add to body class: platform-android
Running command: /Users/Arno/conference/platforms/android/cordova/build
ANDROID_HOME=/Users/Arno/android-sdk-macosx
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Running: /Users/Arno/conference/platforms/android/gradlew cdvBuildDebug -b /Users/Arno/conference/platforms/android/build.gradle -Dorg.gradle.daemon=true
:preBuild
:compileDebugNdk
:preDebugBuild
:checkDebugManifest
:CordovaLib:compileLint
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles
:CordovaLib:preBuild
:CordovaLib:preDebugBuild
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugAidl
:CordovaLib:compileDebugRenderscript
:CordovaLib:generateDebugBuildConfig
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets
:CordovaLib:generateDebugResValues
:CordovaLib:generateDebugResources
:CordovaLib:packageDebugResources
:CordovaLib:processDebugManifest
:CordovaLib:processDebugResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:CordovaLib:processDebugResources’.

com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/Arno/android-sdk-macosx/build-tools/23.0.0/aapt package -f --no-crunch -I /Users/Arno/android-sdk-macosx/platforms/android-22/android.jar -M /Users/Arno/conference/platforms/android/CordovaLib/build/intermediates/bundles/debug/AndroidManifest.xml -S /Users/Arno/conference/platforms/android/CordovaLib/build/intermediates/bundles/debug/res -A /Users/Arno/conference/platforms/android/CordovaLib/build/intermediates/bundles/debug/assets -m -J /Users/Arno/conference/platforms/android/CordovaLib/build/generated/source/r/debug --debug-mode --custom-package org.apache.cordova --non-constant-id -0 apk --output-text-symbols /Users/Arno/conference/platforms/android/CordovaLib/build/intermediates/bundles/debug
Error Code:
139

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 25.908 secs

/Users/Arno/conference/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /Users/Arno/conference/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/Arno/conference/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /Users/Arno/conference/platforms/android/cordova/build: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: /Users/Arno/conference/platforms/android/cordova/build: Command failed with exit code 1
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139: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)

I hope you can give more advice to fix this problem. This problem is frustrating :cry: :cry:

1 Like

I have a similar problem. Have you found the solution?

Same problem here.

david@david-U44SG:~/Programacion/Movil/IonicProjects/myApp$ ionic build android
Running command: /home/david/Programacion/Movil/IonicProjects/myApp/hooks/after_prepare/010_add_platform_class.js /home/david/Programacion/Movil/IonicProjects/myApp
add to body class: platform-android
Running command: /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/cordova/build
ANDROID_HOME=/home/david/Programacion/Movil/android-sdk-linux
JAVA_HOME=/usr/lib/jvm/java-8-oracle
Running: /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/gradlew cdvBuildDebug -b /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/build.gradle -Dorg.gradle.daemon=true
:preBuild
:compileDebugNdk
:preDebugBuild
:checkDebugManifest
:CordovaLib:compileLint
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles
:CordovaLib:preBuild
:CordovaLib:preDebugBuild
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugAidl
:CordovaLib:compileDebugRenderscript
:CordovaLib:generateDebugBuildConfig
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets
:CordovaLib:generateDebugResValues
:CordovaLib:generateDebugResources
:CordovaLib:packageDebugResources
:CordovaLib:processDebugManifest
:CordovaLib:processDebugResources/home/david/Programacion/Movil/android-sdk-linux/build-tools/23.0.1/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:CordovaLib:processDebugResources’.

com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/david/Programacion/Movil/android-sdk-linux/build-tools/23.0.1/aapt package -f --no-crunch -I /home/david/Programacion/Movil/android-sdk-linux/platforms/android-22/android.jar -M /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/CordovaLib/build/intermediates/bundles/debug/AndroidManifest.xml -S /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/CordovaLib/build/intermediates/bundles/debug/res -A /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/CordovaLib/build/intermediates/bundles/debug/assets -m -J /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/CordovaLib/build/generated/source/r/debug --debug-mode --custom-package org.apache.cordova --non-constant-id -0 apk --output-text-symbols /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/CordovaLib/build/intermediates/bundles/debug
Error Code:
127
Output:
/home/david/Programacion/Movil/android-sdk-linux/build-tools/23.0.1/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.124 secs

/home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/cordova/build: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: /home/david/Programacion/Movil/IonicProjects/myApp/platforms/android/cordova/build: Command failed with exit code 1
at ChildProcess.whenDone (/home/david/Programacion/Movil/node-v4.1.1-linux-x64/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:817:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

Hi again,

I finally found a solution, the problem was that I didn’t have intalled some necessary libraries.
I fixed it by installing the following libraries:

  • lib32stdc++6
  • lib32z1

I’m using elementaryOS Freya, a Linux distribution.
I installed them via linux terminal:

  • sudo apt-get install lib32stdc++6
  • sudo apt-get install lib32z1

Source: http://stackoverflow.com/questions/27589844/android-studio-1-0-2-not-building-appmergedebugresources-error

I hope this works for you too.

7 Likes

Hi Dellos7,

thank you for sharing, unfortunately when I try to run your suggestion mac cannot support command apt-get. It said that:
apt-get: command not found

then I try to run using this:
brew install lib32stdc++6
Error: No available formula for lib32stdc++6
==> Searching formulae…
==> Searching taps…

brew install lib32z1
Error: No available formula for lib32z1
==> Searching formulae…
==> Searching taps…

I still try to find out what happen to my developing environment for android.

As you may have already found, this error can be visible due to many reasons. Hence you need to find actual reason behind the error.

Instead of issuing just;

ionic build android

Navigate to platform android folder; normally located in below path

cd [your_project_folder]\platform\android

And issue below command;

gradlew.bat --info build clean

This will list the actual issue, rectify that and redo the build.

Hope this is helpful!

1 Like

I struggled with this problem for days! Thank you so much. Works wonderfully.

In my case, the problem was caused by some files inside my project which had non-UTF8 characters.

I had some pictures named like “instalación.jpg” (the “ó” latin character was causing the issue).

After replacing the names of the files, the build was OK.

2 Likes

Thanks It worked for me on Ubuntu.

Thanks worked for me on Travis (ubuntu 14.04)

I’ve got a similar issue.
To find a workaround, I’ve created a new blank project.
The compilation and emulation was good.
I figure out there were a problem in my www folder.
After some multiples test, one of my picture got that name : 'Clément.png".
Removing the accent to get ‘Clement.png’ just fixed my problem…
A lot of pain.

1 Like

Thank you, man!
I had a similar problem here, and was solved by changing the names of some images that had special characters.

Best Regards!

1 Like

Thanks you @Dellos7.
Your solution works for me.
Ubuntu 14.04

Help me a lot !! Thanks

Thanks worked for me on Travis (ubuntu 16.04)

Hi there,

Little Help would be appreciated :innocent:

I’m new on ionic, ran through the same problem but none of the solutions mentioned above actually worked.

=> Ionic Info

Cordova CLI: 6.3.1
Ionic Framework Version: 1.3.1
Ionic CLI Version: 2.0.0
Ionic App Lib Version: 2.0.0-beta.20
OS: Windows 8.1
Node Version: v4.5.0

LOG on console. ( While executing => ionic build android )

C:\Windows\System32\scotch-todo>ionic build android
Running command: “C:\Program Files\nodejs\node.exe” C:\Windows\System32\scotch-t
odo\hooks\after_prepare\010_add_platform_class.js C:\Windows\System32\scotch-tod
o

add to body class: platform-android

ANDROID_HOME=C:\Users\rshalik\AppData\Local\Android\sdk

JAVA_HOME=C:\Program Files\Java\jdk1.8.0_101

Observed package id ‘add-ons;addon-google_apis-google-23’ in inconsistent locati
on ‘C:\Users\rshalik\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-
23-1’ (Expected ‘C:\Users\rshalik\AppData\Local\Android\sdk\add-ons\addon-google
_apis-google-23’)

Already observed package id ‘add-ons;addon-google_apis-google-23’ in ‘C:\Users\r
shalik\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-23’. Skipping
duplicate at ‘C:\Users\rshalik\AppData\Local\Android\sdk\add-ons\addon-google_ap
is-google-23-1’

Incremental java compilation is an incubating feature.

:preBuild
UP-TO-DATE
:preDebugBuild UP-TO-DATE
:checkDebugManifest
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:compileDebugNdk UP-TO-DATE
:CordovaLib:compileLint
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles
UP-TO-DATE
:CordovaLib:packageDebugRenderscript UP-TO-DATE
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugRenderscript
UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE

:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources UP-TO-DATE
:CordovaLib:compileDebugAidl
UP-TO-DATE
:CordovaLib:generateDebugBuildConfig UP-TO-DATE
:CordovaLib:mergeDebugShaders UP-TO-DATE
:CordovaLib:compileDebugShaders UP-TO-DATE
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets UP-TO-DATE
:CordovaLib:processDebugManifest UP-TO-DATE
:CordovaLib:processDebugResources
FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:CordovaLib:processDebugResources’.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.E
xecException: Process ‘command ‘C:\Users\rshalik\AppData\Local\Android\sdk\build
-tools\23.0.1\aapt.exe’’ finished with non-zero exit value 1

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

BUILD FAILED

Total time: 8.561 secs

Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:CordovaLib:processDebugResources’.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.E
xecException: Process ‘command ‘C:\Users\rshalik\AppData\Local\Android\sdk\build
-tools\23.0.1\aapt.exe’’ finished with non-zero exit value 1

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

=> Looking for your help guys :sweat:

ANDROID STUDIO: v 2.1
Android SDK Tools 25.1.7
Android SDK Platform-tools 24.0.2
Android SDK Build-tools 23.0.1

SDK Platform API 23 Rev.3
SDK Platform API 22 Rev.2

Hi,

try removing SDK Platform API 23 Rev.3 and compile again.

Thankyou :slight_smile: akilud, for your fast reply…

I did what you suggested and got following LOG…
=> I removed SDK Platform API 23 Rev.3 and compiled again

CONSOLE LOG:

C:\Windows\System32\scotch-todo>ionic build android
Running command: “C:\Program Files\nodejs\node.exe” C:\Windows\System32\scotch-t
odo\hooks\after_prepare\010_add_platform_class.js C:\Windows\System32\scotch-tod
o

add to body class: platform-android

ANDROID_HOME=C:\Users\rshalik\AppData\Local\Android\sdk

JAVA_HOME=C:\Program Files\Java\jdk1.8.0_101

Observed package id ‘add-ons;addon-google_apis-google-23’ in inconsistent locati
on ‘C:\Users\rshalik\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-
23-1’ (Expected ‘C:\Users\rshalik\AppData\Local\Android\sdk\add-ons\addon-google
_apis-google-23’)

Already observed package id ‘add-ons;addon-google_apis-google-23’ in ‘C:\Users\r
shalik\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-23’. Skipping
duplicate at ‘C:\Users\rshalik\AppData\Local\Android\sdk\add-ons\addon-google_ap
is-google-23-1’

BUILD FAILED

Total time: 9.169 secs

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘android’.

failed to find target with hash string ‘android-23’ in: C:\Users\rshalik\AppDa
ta\Local\Android\sdk

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘android’.

failed to find target with hash string ‘android-23’ in: C:\Users\rshalik\AppDa
ta\Local\Android\sdk

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.
    Please install Android target: “android-23”.

Hint: Open the SDK manager by running: “C:\Users\rshalik\AppData\Local\Android\s
dk\tools\android.bat”
You will require:

  1. “SDK Platform” for android-23
  2. "Android SDK Platform-tools (latest)
  3. “Android SDK Build-tools” (latest)

Could you please shed some light where do i go from here now :innocent:

Thankyou so much for your speedy help…

Hi,

Looks like the app needs SDK Platform API 23, so you should install it again, sorry,

I had this problem before and it was because i updated one of the packages, i think it was the build tools version 23, not platform api 23.

So you can try to remove the build tools v23 , make sure that v22 of build tools is installed.