Ionic android build error (worked previously)

Been banging my head on this one for a while. This used to work but now it’s giving me this issue. I’ve tried:

  • ./platforms/android/cordova/clean
  • removing android platform, clean, reinstall
  • removing / adding most recent plugin

Here’s the error I’m getting:

$ ionic build android
Updated the hooks directory to have execute permissions
Running command: "/Users/MeTheUser/Sites/TheSite/MyApp/hooks/after_prepare/010_add_platform_class.js" "/Users/MeTheUser/Sites/TheSite/MyApp/"
add to body class: platform-android
Running command: "/Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/cordova/build" 
ANDROID_HOME=/Volumes/Mac/.android
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Running: /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/gradlew cdvBuildDebug -b /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build.gradle -Dorg.gradle.daemon=true
:preBuild
:compileDebugNdk UP-TO-DATE
:preDebugBuild
:checkDebugManifest
:CordovaLib:compileLint
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles UP-TO-DATE
:CordovaLib:preBuild
:CordovaLib:preDebugBuild
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugAidl UP-TO-DATE
:CordovaLib:compileDebugRenderscript UP-TO-DATE
:CordovaLib:generateDebugBuildConfig UP-TO-DATE
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE
:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources UP-TO-DATE
:CordovaLib:processDebugManifest UP-TO-DATE
:CordovaLib:processDebugResources UP-TO-DATE
:CordovaLib:generateDebugSources UP-TO-DATE
:CordovaLib:compileDebugJava UP-TO-DATE
:CordovaLib:processDebugJavaRes UP-TO-DATE
:CordovaLib:packageDebugJar UP-TO-DATE
:CordovaLib:compileDebugNdk UP-TO-DATE
:CordovaLib:packageDebugJniLibs UP-TO-DATE
:CordovaLib:packageDebugLocalJar UP-TO-DATE
:CordovaLib:packageDebugRenderscript UP-TO-DATE
:CordovaLib:bundleDebug UP-TO-DATE
:prepareAndroidCordovaLibUnspecifiedDebugLibrary UP-TO-DATE
:prepareDebugDependencies
:compileDebugAidl UP-TO-DATE
:compileDebugRenderscript UP-TO-DATE
:generateDebugBuildConfig UP-TO-DATE
:generateDebugAssets UP-TO-DATE
:mergeDebugAssets UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:mergeDebugResources
:processDebugManifest UP-TO-DATE
:processDebugResources/Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build/intermediates/res/debug/values/values.xml:2: error: Error parsing XML: prefix must not be bound to one of the reserved namespace names

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
  	/Volumes/Mac/.android/build-tools/21.1.2/aapt package -f --no-crunch -I /Volumes/Mac/.android/platforms/android-22/android.jar -M /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build/intermediates/manifests/full/debug/AndroidManifest.xml -S /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build/intermediates/res/debug -A /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build/intermediates/assets/debug -m -J /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build/generated/source/r/debug -F /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build/intermediates/res/resources-debug.ap_ --debug-mode --custom-package com.thecompany.theapp -0 apk --output-text-symbols /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build/intermediates/symbols/debug
  Error Code:
  	1
  Output:
  	/Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build/intermediates/res/debug/values/values.xml:2: error: Error parsing XML: prefix must not be bound to one of the reserved namespace names
  	


* 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: 16.044 secs

/Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                          ^
Error code 1 for command: /Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/MeTheUser/Sites/TheSite/MyApp/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /Users/MeTheUser/Sites/TheSite/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: /Users/MeTheUser/Sites/TheSite/MyApp/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:131:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1008:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1080:5) 
  • ionic v1.5.0
  • cordova v5.0.0

Hmm, could you paste the output from $ ionic info?
Also check to see if you android tools are up to date but running android

$ ionic info

Your system information:

Cordova CLI: 5.0.0
Ionic Version: 1.0.0-rc.2
Ionic CLI Version: 1.5.0
Ionic App Lib Version: 0.1.0
ios-deploy version: Not installed
ios-sim version: 3.1.1
OS: Mac OS X Yosemite
Node Version: v0.12.1
Xcode version: Xcode 6.3.1 Build version 6D1002

I upgraded the Android tools last night but I just checked the $ android sdk and there are three more updates. I’ll let you know what happens after I update.

After getting updates from Android SDK I’m running into the same error as the original one posted.

Android SDK Tools r24.3.2
Android SDK Platform Tools r22

What’s in that values.xml? This is one of the few possibly related topics I could find:

Thanks @encodedmirko I had actually found that link before posting my question here. My values.xml lines were a little different but there was still a custom namespace that went unused. The issue is that whenever I run ionic build android again it recreates this file just as it was.

Here’s what the file looks like and you can see the offending line on 2 with xmlns:ns1="..."

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:ns1="http://www.w3.org/2000/xmlns/">
    <!-- From: file:/Users/MyUser/MyApp/platforms/android/res/values/strings.xml -->
    <eat-comment/>
    <string name="activity_name">@string/launcher_name</string>
    <string name="app_name">MyApp</string>
    <!-- From: file:/Users/MyUser/MyApp/platforms/android/res/values/com_crashlytics_export_strings.xml -->
    <eat-comment/>
    <string name="com.crashlytics.android.build_id" ns1:ignore="UnusedResources,TypographyDashes" translatable="false" ns1:ns0="http://schemas.android.com/tools">09daa730-6735-4563-a2cc-06af907fddbb</string>
    <!-- From: file:/Users/MyUser/MyApp/platforms/android/res/values/strings.xml -->
    <eat-comment/>
    <string name="launcher_name">@string/app_name</string>
</resources>

Looks like it may be something to do with the crashlytics plugin. What if you try removing that plugin, does it build fine?

Hmm, good clue. I removed the plugin then ran .platorms/android/cordova/clean but got the same crash on build and when I checked the values.xml it still had cordova residue in it. Do you think there’s a better strategy to try?

as further FYI here’s my plugin list after removing crashlytics:

$ cordova plugin list
com.google.playservices 19.0.0 "Google Play Services for Android"
com.ionic.deploy 0.1.5 "IonicDeploy"
com.ionic.keyboard 1.0.4 "Keyboard"
com.phonegap.plugins.PushPlugin 2.4.0 "PushPlugin"
cordova-plugin-directions 0.3.1 "Directions"
cordova-plugin-google-analytics 0.7.2 "Google Universal Analytics Plugin"
cordova-plugin-network-information 1.0.1-dev "Network Information"
cordova-plugin-whitelist 1.0.1-dev "Whitelist"
org.apache.cordova.console 0.2.13 "Console"
org.apache.cordova.device 0.3.0 "Device"
org.apache.cordova.device-motion 0.2.11 "Device Motion"
org.apache.cordova.device-orientation 0.3.11 "Device Orientation"
org.apache.cordova.geolocation 0.3.12 "Geolocation"
org.apache.cordova.network-information 0.2.15 "Network Information"

Odd, it seemed that the ns1 namespace was only used by the crashlytics string. In fact here’s somebody else reporting a similar issue

Ah, the joys of xml. I’m out of ideas right now. Maybe do a global search inside the project and find where those values with the namespace come from, e.g. TypographyDashes.

I fixed it. If I remember correctly, here’s what I tried: (submitted same answer to SOF)

  • ionic build android (failure)
  • ionic platform remove android
  • cordova platform remove android
  • cordova plugin remove cordova-crashlytics-plugin
  • (might have to skip this step) ./platforms/android/cordova/clean
  • cordova platform add android
  • ionic build android (success)
  • cordova plugin add https://github.com/4sh-projects/cordova-crashlytics-plugin
  • ionic build android (success)

Hi,

I am facing the same issue. I am not able get ahead with any of the solutions mentioned. Please help me with this. Thank you.

ionic info:

Your system information:

Cordova CLI: 5.3.3
Ionic Version: 1.1.0
Ionic CLI Version: 1.6.5
Ionic App Lib Version: 0.3.9
OS: null
Node Version: v4.1.1

C:\Windows\System32\myapp>ionic build android
Running command: “C:\Program Files\nodejs\node.exe” C:\Windows\System32\myapp\hooks\after_prepare\010_add_platform_class.js C:\Windows\System32\myapp
add to body class: platform-android
Running command: cmd “/s /c “C:\Windows\System32\myapp\platforms\android\cordova\build.bat””
ANDROID_HOME=C:\Users\Keerthi\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk1.7.0_79
Running: C:\Windows\System32\myapp\platforms\android\gradlew cdvBuildDebug -b C:\Windows\System32\myapp\platforms\android\build.gradle -Dorg.gradle.daemon=true
:preBuild
:compileDebugNdk UP-TO-DATE
:preDebugBuild
:checkDebugManifest
:CordovaLib:compileLint
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles UP-TO-DATE
:CordovaLib:preBuild
:CordovaLib:preDebugBuild
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugAidl UP-TO-DATE
:CordovaLib:compileDebugRenderscript UP-TO-DATE
:CordovaLib:generateDebugBuildConfig UP-TO-DATE
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE
:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources UP-TO-DATE
:CordovaLib:processDebugManifest UP-TO-DATE
:CordovaLib:processDebugResourcesERROR: asset directory ‘C:\Windows\System32\myapp\platforms\android\CordovaLib\build\intermediates\bundles\debug\assets’ does not exist 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:
C:\Users\Keerthi\AppData\Local\Android\sdk\build-tools\23.0.1\aapt.exe package -f --no-crunch -I C:\Users\Keerthi\AppData\Local\Android\sdk\platforms\android-23\android.jar -M C:\Windows\System32\myapp\platforms\android\CordovaLib\build\intermediates\bundles\debug\AndroidManifest.xml -S C:\Windows\System32\myapp\platforms\android\CordovaLib\build\intermediates\bundles\debug\res -A C:\Windows\System32\myapp\platforms\android\CordovaLib\build\intermediates\bundles\debug\assets -m -J C:\Windows\System32\myapp\platforms\android\CordovaLib\build\generated\source\r\debug --debug-mode --custom-package org.apache.cordova --non-constant-id -0 apk --output-text-symbols C:\Windows\System32\myapp\platforms\android\CordovaLib\build\intermediates\bundles\debug
Error Code:
1
Output:
ERROR: asset directory ‘C:\Windows\System32\myapp\platforms\android\CordovaLib\build\intermediates\bundles\debug\assets’ does not exist

  • 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.784 secs

C:\Windows\System32\myapp\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c “C:\Windows\System32\myapp\platforms\android\gradlew cdvBuildDebug -b C:\Windows\System32\myapp\platforms\android\build.gradle -Dorg.gradle.daemon=true”
ERROR building one of the platforms: Error: cmd: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: cmd: Command failed with exit code 1
at ChildProcess.whenDone (C:\Users\Keerthi\AppData\Roaming\npm\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)

have axactly the same issue, did you solve it?

This was caused because of permissions on folder for me. Application was not able to create the assets folder. I gave full permissions to the android sdk folder. Then it started working.

1 Like

I need help , my application gives me error to build the apk, thank you

Native thread-sleep not available.
This will result in much slower performance, but it will still work.
You should re-install spawn-sync or upgrade to the lastest version of node if possible.
Check /usr/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/cross-spawn/node_modules/spawn-sync/error.log for more details
Running command: /var/www/html/appLaca/hooks/after_prepare/010_add_platform_class.js /var/www/html/appLaca
add to body class: platform-android
ANDROID_HOME=/home/jcoreas/Android/Sdk
JAVA_HOME=/usr/lib/jvm/java-8-oracle
:preBuild UP-TO-DATE
:preReleaseBuild UP-TO-DATE
:checkReleaseManifest
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preReleaseBuild UP-TO-DATE
:CordovaLib:compileReleaseNdk UP-TO-DATE
:CordovaLib:compileLint
:CordovaLib:copyReleaseLint UP-TO-DATE
:CordovaLib:mergeReleaseProguardFiles UP-TO-DATE
:CordovaLib:packageReleaseRenderscript UP-TO-DATE
:CordovaLib:checkReleaseManifest
:CordovaLib:prepareReleaseDependencies
:CordovaLib:compileReleaseRenderscript UP-TO-DATE
:CordovaLib:generateReleaseResValues UP-TO-DATE
:CordovaLib:generateReleaseResources UP-TO-DATE
:CordovaLib:packageReleaseResources UP-TO-DATE
:CordovaLib:compileReleaseAidl UP-TO-DATE
:CordovaLib:generateReleaseBuildConfig UP-TO-DATE
:CordovaLib:generateReleaseAssets UP-TO-DATE
:CordovaLib:mergeReleaseAssets UP-TO-DATE
:CordovaLib:processReleaseManifest UP-TO-DATE
:CordovaLib:processReleaseResources UP-TO-DATE
:CordovaLib:generateReleaseSources UP-TO-DATE
:CordovaLib:compileReleaseJavaWithJavac UP-TO-DATE
:CordovaLib:processReleaseJavaRes UP-TO-DATE
:CordovaLib:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:CordovaLib:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
:CordovaLib:mergeReleaseJniLibFolders UP-TO-DATE
:CordovaLib:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
:CordovaLib:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
:CordovaLib:bundleRelease UP-TO-DATE
:prepareAndroidCordovaLibUnspecifiedReleaseLibrary UP-TO-DATE
:prepareReleaseDependencies
:compileReleaseAidl UP-TO-DATE
:compileReleaseRenderscript UP-TO-DATE
:generateReleaseBuildConfig UP-TO-DATE
:generateReleaseAssets UP-TO-DATE
:mergeReleaseAssets UP-TO-DATE
:generateReleaseResValues UP-TO-DATE
:generateReleaseResources UP-TO-DATE
:mergeReleaseResources UP-TO-DATE
:processReleaseManifest UP-TO-DATE
:processReleaseResources FAILED

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ‘:processReleaseResources’.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/home/jcoreas/Android/Sdk/build-tools/23.0.3/aapt’’ 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: 1.959 secs
Error: Error code 1 for command: /var/www/html/appLaca/platforms/android/gradlew with args: cdvBuildRelease,-b,/var/www/html/appLaca/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true