Cordova Emulate Error


#1

Following the installation tutorial I have been able to execute the “cordova build” command. When I then try the next emulate command I get the following:

cordova emulate android
Generating config.xml from defaults for platform "android"
Preparing android project
Running on emulator for platform “android” via command “/Users/SM/Desktop/projects/devAPIS/hybrid-iconic/hello/platforms/android/cordova/run” --emulator
[Error: An error occurred while emulating/deploying the android project.
/Users/SM/Desktop/projects/devAPIS/hybrid-iconic/hello/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error executing “adb devices”: /bin/sh: adb: command not found

]

Is this something I can fix via the “android” command. What piece am I missing?


#2

You need to add the platform-tools to your PATH, in Mac is in /Applications/Android Studio.app/sdk/platform-tools


#3

Why would I need the Android Studio App?

There is already a adb command located in the Android SDK API 17 I have installed:

adt-bundle/sdk/platform-tools/adb

My path below already points to the platform-tools and is working for all other commands:

export PATH=$PATH:/Users/SM/Desktop/projects/devSDKS/adt-bundle/sdk/platform_tools:/Users/SM/Desktop/projects/devSDKS/adt-bundle/sdk/tools

Using the android SDK manager I saw that I have API 17 installed but the API 19 version of the Android SDK Build-Tools. So I remove it and install the Android SDK Build-Tools for API 17. This does not make a difference and I still get the following error:

cordova emulate android
Generating config.xml from defaults for platform "android"
Preparing android project
Running on emulator for platform “android” via command “/Users/SuperstringMedia/Desktop/projects/devAPIS/hybrid-iconic/hello/platforms/android/cordova/run” --emulator
[Error: An error occurred while emulating/deploying the android project.
/Users/SuperstringMedia/Desktop/projects/devAPIS/hybrid-iconic/hello/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error executing “adb devices”: /bin/sh: adb: command not found

]

Stuck…


#4

There is a comment in the Android SDK tools directory about having moved adb to the platform-tools directory and indeed it is there.

The error I’m getting seems to indicate that Cordova does not now where to find the adb command? Does it know about this move?

Surely I’m not far from a solution, awaiting advice…


#5

But can you execute the adb command from the terminal?, if that is working fine then maybe is a bigger issue with your SDK or something, I can’t help you more than that


#6

Finally cd’ed into the platform-tools directory and ran ./adb --help. Worked fine, from there I came to the quick conclusion that I had modified a path string and it had a typo.

So, good news is it is fixed and I’m now running the emulator, however it now opens fairly fast and the title shows in the Apple menu bar area and then it dies right away. Tried it a few times with same result, it flashes open then closes right away.

Any ideas on why?

The following just hangs in the terminal with the cursor blinking even after the emulator dies:

cordova emulate android
Generating config.xml from defaults for platform "android"
Preparing android project
Running on emulator for platform “android” via command “/Users/SM/Desktop/projects/devAPIS/hybrid-iconic/hello/platforms/android/cordova/run” --emulator


#7

Can you run and emulator just using the emulator command?, something like:

emulator -avd VIRTUAL_DEVICE_NAME

If not your virtual device isnt configured correctly.


#8

Thanks, l used “android avd” to define a new device according to link called “how-can-i-create-a-avd-for-samsung-galaxy-note-2” on stackoverflow. Sorry I can’t paste whole link because of the extra images it add and which this forum does not allow. I also deleted the default virtual device called MyAvd0.

I then tried “cordova emulate android” and after a VERY long time (more than 5 minutes for sure) I finally saw the OS and then after more waiting the basic app with the Cordova icon being emulated.

Is there any way at all to accelerate the emulation speed? Does setting the memory of a virtual device need to be set to 2 GB’s, does this size also serve to slow down the emulation? Any emulation tips are appreciated!

On the other hand running it direct on my Note II work quite well. Hopefully, when working in Iconic the app will refresh itself automatically whenever changes are make!


#9

You can install the Intel HAXM, look for a tutorial is very easy and you can speed up the emulator.


#10

Thanks, installed HAXM. Now just waiting for word on why Angular is not working for me, see the Angular Not Working topic for status.


#11

Just commenting in case search brings another user here: I was getting the same ‘adb not found’ error when I tried to build the Ionic seed app for Android. I couldn’t work it out, because I’ve been building Phonegap Android apps with no problem with my existing export PATH. But updating it according to the pattern above, and double-checking every character in the string, fixed the problem and I am now able to build & emulate.

Don’t know why my previous PATH worked for Phonegap but not Ionic/Cordova, but glad to have worked it out without too many hours down the hole.

Thanks for the useful info in this thread!


#12

[Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]
ERROR building one of the platforms: Error: /home/sandim/projects/soucgApp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/sandim/projects/soucgApp/platforms/android/cordova/build: Command failed with exit code 2
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)