25
votes

cordova build android gives me the following err

node_modules/q/q.js:126 throw e; (*error details)

This question has been asked before, but the typical answer regarding PATH and ANDROID_HOME hasn't worked for me.

I've put this into code snippet to avoid SO submission problems

export HOME="/Users/rover"
export ANDROID_SDK="$HOME/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk"
export ANDROID_HOME="$ANDROID_SDK/tools"
export ANDROID_PLATFORM_TOOLS="$ANDROID_SDK/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$ANDROID_SDK/build-tools:$PATH"
export ANT_HOME="/usr/local/bin/ant"
#export PATH="$PATH:$ANT_HOME/bin"

My environment variables:

$ set | grep "ANDROID\|PATH"

ANDROID_HOME=/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk/tools ANDROID_PLATFORM_TOOLS=/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk/platform-tools ANDROID_SDK=/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk PATH=/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk/tools:/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk/platform-tools:/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk/build-tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

$ which ant
/usr/local/bin/ant
$ ls /usr/local/bin/ant
/usr/local/bin/ant

$ cordova --version
4.0.0

$ ant -v
Apache Ant(TM) version 1.9.4

I'm on Mac OSX 10.10 (Yosemite) which might have a problem with Java 8. Can this be related?

$ java -version java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

$ ant --execdebug
exec "/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/bin/java" -classpath "/usr/local/Cellar/ant/1.9.4/libexec/lib/ant-launcher.jar" -Dant.home="/usr/local/Cellar/ant/1.9.4/libexec" -Dant.library.dir="/usr/local/Cellar/ant/1.9.4/libexec/lib" org.apache.tools.ant.launch.Launcher -cp ""

(*error details)

BUILD FAILED
/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk/tools/ant/build.xml:653: The following error occurred while executing this line:
/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk/tools/ant/build.xml:698: null returned: 1

Total time: 1 second

/Library/WebServer/Documents/Booster/core_ionic_git/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                          ^
Error code 1 for command: ant with args: debug,-f,/Library/WebServer/Documents/Booster/core_ionic_git/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /Library/WebServer/Documents/Booster/core_ionic_git/platforms/android/cordova/build: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

Any ideas on fixing this?

8

8 Answers

9
votes

I noticed that your ANDROID_HOME variable might be incorrectly setup - as far as I can tell, it should be set to the root of your SDK folder (what you have ANDROID_SDK set to), try that (and make sure that you still have both $ANDROID_HOME/tools and $ANDROID_HOME/platform-tools on your path).

20
votes

I banged my head against the wall for hours and hours and ultimately came up with a simple solution. I went into the project directory and issued two commands:

cordova platform remove android
cordova platform add android

Recompiled with "cordova build android" and it worked like a charm.

I think cordova wanted to possibly update some files.

===== Update for Ionic ========

In case you are using ionic framework then these are the commands for your rescue:

ionic platform remove android
ionic platform add android

I have noticed that this normally happens when you break (Ctrl-C) the compilation process.

2
votes

I run in the same problem and solved it by escaping non-letter characters in config.xml. Particulary for the name attribute:

<name>Temps d'espera</name>

I changed it to:

<name>Temps d\'espera</name>

And then it run perfectly. Hope it helps.

1
votes

@mylord I had similar error and it was due to invalid debug certificate. On Linux Delete ~/.android debug.keystore file.

The next time you build, the build tools will regenerate a new keystore and debug key.

This solved for me. I hope this helps.

1
votes

I ran into this same problem while running 'phonegap serve', but the solution was very different. I noticed that operation would work when I restarted my computer. In case anyone else runs into this problem. Here is the solution on Ubuntu 15

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

which was taken from the stackoverflow thread Grunt watch error - Waiting...Fatal error: watch ENOSPC

In addition to the posters error, I had the error

at exports._errnoException (util.js:856:11)
at FSWatcher.start (fs.js:1313:19)
at Object.fs.watch (fs.js:1341:11)

further down.

0
votes

I meet same error message, but my ANDROID_HOME setting is correct. I find the error is caused by I opening a .apk file in the \platforms\android\ant-build folder. After I close 7zip that occupy the .apk file, ant build passed.

0
votes

Before changing anything, make an empty cordova project and try to build it and you can figure out the problem is project specific or not.

After a lot of change i made, i figured out we shouldn't have two folders with same names : jquery and jQuery!

0
votes

I had the same issue. It was caused by having an App with the same name (and the same reverse style domain name in my case) installed on the Android Device which originated from the Google Play store (it was our Beta release).