25

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?

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
mylord
  • 699
  • 2
  • 12
  • 20

8 Answers8

20

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.

AnR
  • 1,809
  • 3
  • 26
  • 45
  • Thanks! Yes, I'm having trouble with my npm install as well. When I try to update cordova project, I get e.g. shelljs missing, and to install basically anything, npm is complaining of unmet dependencies etc... but that's another bug to hunt down :) – mylord Jan 02 '15 at 08:59
  • 1
    If you could just re-install it should work I think. I have re-installed nodejs as well. – AnR Jan 02 '15 at 09:30
  • 1
    I have noticed one more thing also, after removing and adding Android platform. The output Apk file name apparently has also changed. Previously I used to get MyAppName-debug.apk. Now it is CordovaApp-debug.apk. This info would be helpful if you are using a DOS batch file to automate the process. – AnR Jan 02 '15 at 09:34
  • I've ionic installed but command doesn't execute in my env. What should I need to add my path? Even though I have added all needed paths I get same error. This either didn't work for me. Cordova tutorial and ionic tutorial and these all answers didn't helped me much for this interesting `q.js:126` problem. Build doesn't work. But I can work with eclipse and test it on device or emu. – Davut Gürbüz Jul 24 '15 at 15:07
  • I've discovered the real cause after commenting the line and solved by this http://stackoverflow.com/a/16631694/413032 – Davut Gürbüz Jul 24 '15 at 15:34
  • Thank you very much. My solution is: `phonegap platform remove android` `phonegap platform add android` – Bishal Paudel Sep 11 '15 at 12:08
9

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).

Marxama
  • 425
  • 3
  • 13
  • I did download Java 6 for OSX at Yosemite because Eclipse complained it needed it. I'll try to set my Java to that, but it's a strange error to get if that's the problem. – mylord Nov 07 '14 at 11:12
  • Yes, you're right, I had a similar error with the "q.js:126" error message, but turns out that's a very generic place for errors to occur (if I recall, it calls some external program, in this case ant I'd suppose). I may have found the solution in another question: Close Eclipse and run ant clean in your project folder. http://stackoverflow.com/questions/23753320/build-error-referencing-build-xml-and-proguard-file-null-returned-1/23774435#23774435 – Marxama Nov 12 '14 at 08:16
  • ant clean gives: Buildfile: build.xml does not exist! The only build.xml I have in my project are related to the facebookconnect plugin. Any other ideas? – mylord Nov 12 '14 at 22:21
  • 1
    Right, sorry - you'd need to go to (from your project root) platforms/android, the build.xml should be there. If it's not, or if you can't clean it, then you might want to try and re-create the project using Java 6 or 7. Also, 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) – Marxama Nov 13 '14 at 06:44
  • Fixed by, as you said, changing to ANDROID_HOME=/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk fixed the problem for a *new* project. My other project with facebook plugin (and its own ant or something) still not working but that's another problem. Do you want to make an answer so I can set it as the solution? – mylord Dec 12 '14 at 10:21
  • Sure mate, I edited this one! As for it not having effect on your old project - not sure what the reason might be, but I've had similar problems where recreating a project from scratch resolved build issues. – Marxama Dec 12 '14 at 13:37
  • I'm having this issue.I have android platform for my project but have `build.gradle` instead of xml. Getting the same error. Any idea ? – Davut Gürbüz Jul 24 '15 at 14:53
  • I've discovered the real cause after commenting the line in q.js and solved by this http://stackoverflow.com/a/16631694/413032 – Davut Gürbüz Jul 24 '15 at 15:35
2

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.

Enric Mieza
  • 342
  • 2
  • 10
1

@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.

bonitarunner
  • 241
  • 1
  • 2
  • 1
    I moved that file and ran: cordova build android. Same error persists. Also, no other debug.keystore was generated. +1 for help anyhow. Any other ideas? – mylord Nov 12 '14 at 22:19
1

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.

Community
  • 1
  • 1
user3071643
  • 1,405
  • 1
  • 15
  • 18
0

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.

wangf
  • 895
  • 9
  • 12
0

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!

Ghominejad
  • 1,572
  • 16
  • 15
0

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).

user3094755
  • 1,561
  • 16
  • 20