On Windows with Node.js 6.9.5 and NativeScript CLI 2.5.0
Steps to reproduce:
Meanwhile, CLI is hanging on:
D:\repositories\nativescript-sdk-examples-ng>tns run android
Skipping prepare.
Searching for devices...
Starting Android emulator with image API23
Hello,
I am new to NativeScript and have been trying to go through the setup information on the website here: https://docs.nativescript.org/angular/tutorial/ng-chapter-1 I am experiencing the exact same problem as described above. Is there any solution to this? - It seems the problem comes from the nativescript-sdk-examples-ng kit
After waiting for the timeout option to kick in, I get the following output
>tns run android --timeout 300
Searching for devices...
Starting Android emulator with image Xamarin_Android_API_23
Cannot find connected devices.
Emulator start failed with: Cannot run your app in the native emulator. Increase the timeout of the operation with the --timeout option or try to restart your adb server with 'adb kill-server' command. Alternatively, run the Android Virtual Device manager and increase the allocated RAM for the virtual device.
To list currently connected devices and verify that the specified identifier exists, run 'tns device'.
To list available emulator images, run 'tns device <Platform> --available-devices'.
npm - 5.6.0
node - v6.9.5
nts - 3.4.0
Cheers,
Hi @KristiyanFxy,
can you explain in detail what exactly is the behavior you encounter? Try running tns run android --log trace and post the result here, after your explanation on the issue.
Hi @Plamen5kov,
Thanks for the prompt reply. My issue is when I try to run tns run android --timeout 300 or tns run android --avd [different available emulator] the console freezes i.e. CTRL + C does not stop the process and eventually writes out the following:
Z:\Work\Work 2018\Associations-Game_repository\Associations-game>tns run android
Searching for devices...
Starting Android emulator with image Xamarin_Android_API_23
Cannot find connected devices.
Emulator start failed with: Cannot run your app in the native emulator. Increase the timeout of the operation with the --timeout option or try to restart your adb
server with 'adb kill-server' command. Alternatively, run the Android Virtual Device manager and increase the allocated RAM for the virtual device.
To list currently connected devices and verify that the specified identifier exists, run 'tns device'.
To list available emulator images, run 'tns device--available-devices'.
That is pretty odd because I have 9GB ram left available and nor my CPU or RAM spike. I tried the suggestions from #2210 & #2092 without success.
To reproduce the problem I follow the steps found here: https://docs.nativescript.org/angular/tutorial/ng-chapter-1
tns create [gameName]--template nativescript-template-ng-tutorialcd [gameName]tns run android@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://www.nativescript.org/setup/win'))"Either this is a very specific problem or it is related to my development environment - either way, any suggestions will be much appreciated!
cmd output ------------------------------------------------------------
Z:\Work\Work 2018\Associations-Game_repository\Associations-game>tns run android --log trace
Loading extensions.
execFile: C:\Androidandroid-sdk\platform-toolsadb "help"
Exec npm -v
stdout: 5.6.0
stderr:
spawn: java "-version"
Exec node-gyp -v
stdout:
stderr: 'node-gyp' is not recognized as an internal or external command,
operable program or batch file.
Error while executing node-gyp -v: Command failed: node-gyp -v
'node-gyp' is not recognized as an internal or external command,
operable program or batch file.
Exec "C:\Androidandroid-sdk\platform-toolsadb" version
stdout: Android Debug Bridge version 1.0.39
Version 0.0.1-4500957
Installed as C:\Androidandroid-sdk\platform-toolsadb.exe
stderr:
spawn: C:\Androidandroid-sdk\tools\emulator "-help"
Result when throw error is false:
{ stdout: 'Android Emulator usage: emulator [options] [-qemu args]\r\n options:\r\n -list-avds list available AVDs\r\n -sysdir
@KristiyanFxy while I try to reproduce your issue, can you run tns doctor so we make sure that your development environment is set up correctly. As you say there might be a problem with the setup script, so I want to get that out of the way before we move forward.
Which version of CLI are you using: tns --version?
Can you try to start an emulator manually, and then run the command: tns run android as it should find any device that's attached and authorized or emulator that's started and ready to use?
Most likely it's a problem with the environment set up, so you could try following these steps in order to setup your machine: https://docs.nativescript.org/start/ns-setup-win
Hi @Plamen5kov,
First, thank you for your help and I have found the solution to multiple problems people are experiencing when trying to set up their environment.
The problems I incurred:
tns doctor not finding any problems but tns run android --timeout 300 times out with error.tns run android throws Java (javac) error.When I was trying to run an android emulator using AVD Manager, as Administrator, I was getting a back screen. The reason was that I did not have all the necessary Android SDK packets. This might be because I already had Visual Studio & c# Xamarin extension installed that after running @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://www.nativescript.org/setup/win'))" confused the hell out of my Android emulator.
Quick caviate: If you do not install HAXM, you will see the following message when trying to run the emulator: "Please encure Intel HAXM is properly Installed and usable. CPU acceleration status: HAXM is not installed on this machine"
Note: I have plenty of RAM so I left the default RAM amount, but you might need to edit that for your specific system. That being said, I increase VM Heap to 512 because the virtual machine was not loading.
My uneducated assumption in my case the problem was forcing my old CPU I5-3750k to calculate polygons which the processor is not very successful at.
tns doctor not finding any problems but tns run android --timeout 300 times out with error.This was a tricky one and I have no idea what causes the problem but I have found a workaround (unless that is how NativeScript is intended to be used).
Now for this to work you will need to manually start your emulator and then instruct NativeScript to run your program.
What I noticed is that when the emulator is not running, executing 'tns devices returns "Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again."

That being said, after using the workaround mentioned bellow, tns finds the emulator.

tns run android --timeout 100Note: At this point you might find that the NativeScript is running to a "Build Error" and it is exiting. Now... that is documented here #2092. I found that creating a fresh TNS project works best than amending package.json, but you are welcome to do either.

As explained by @Plamen5kov in ticket #2092 the problem is due to conflicting jars.
Easiest fix is to build a new app from scratch and port your scripts. alternatively you can follow the steps from ticket #2092 by @Pip3r4o
"tns-android": "^2.2.0" from Dependenciesnode_modules and the platforms directoriestns run androidtns run android throws Java (javac) error.This was caused by the installer skipping jdk8 installation because I already had it installed, unfortunately, the current installation was causing problems.
You will need to force install jdk8
choco install jdk8 -ytns run androidThe problem is with the development environment, that being said I hope my comment will help in the future others.

Cheers,
@KristiyanFxy, let me just say waw! Great explanation. I commend you for taking the time to explain all the steps to fix issues users might have. I'll link this answer to the FAQs.
I was having the same problem, same error, and what was missing was the actual "emulator" package from android.
I installed it with:
sdkmanager emulator
And now it works.
Running tnd doctor did not show any problems, so it took me a while to find the problem.
@Plamen5kov I want to ask a simple question. After running the command in CMD
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://www.nativescript.org/setup/win'))"
Do I again need to install Android studio and AVD explicitly?
Because, when I'm trying to run cmd tns run android it is showing Error... I'm attaching the screenshot of my CMD. Please help me fix this...

@yashwp did you find the solution? I have the same outcome.
@yashwp Same here :(
I was learning swift to generate IOS apps for the past three weeks and have installed x-code prior to learning nativescript. I notice the root of the problem to be from the set-up to install nativescript CLI as it was instructed to do so in the step by step installation we all encountered during the process where it asks us if we have x-code installed. Since I did, i selected Yes and the process skipped that part.
The path becomes the problem and according to StackOverflow:
"This problem happens when xcode-select developer directory was pointing to /Library/Developer/CommandLineTools, when a full regular Xcode was required (happens when CommandLineTools are installed after Xcode)"
Although his solution did not help me. I found that resetting the xcode-select path would and did it.
The solution that worked for me is to reset the path and so you dont have to re-install xcode. Run this line:
sudo xcode-select -r
Im also using MacOS, and the android package wasnt on the right path. This did it for me from terminal:
pico ~/.bash_profile
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export ANDROID_SDK_HOME=/Users/$USER/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/$USER/.android/avd
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_AVD_HOME
source ~/.bash_profile
----\
I was running 'tns run android --bundle' in visual code studio terminal or android studio terminal that continued to fail. So I run it from the terminal and executes android emulator successfully. Why is this? I am not sure yet.
@IamGiel @mesterm Sorry for the late reply. I have tried to re-install the using those scripts and it works for me thereafter. I would say make sure your other dependencies are updated
Thank you @IamGiel. I was also using VSCode and tns run android --bundle kept failing again and again... Until I updated the variables 馃
You will also receive this error if emulator.exe does not exist here:
C:\Androidandroid-sdk\emulator\emulator.exe
Most helpful comment
I was learning swift to generate IOS apps for the past three weeks and have installed x-code prior to learning nativescript. I notice the root of the problem to be from the set-up to install nativescript CLI as it was instructed to do so in the step by step installation we all encountered during the process where it asks us if we have x-code installed. Since I did, i selected Yes and the process skipped that part.
The path becomes the problem and according to StackOverflow:
"This problem happens when xcode-select developer directory was pointing to /Library/Developer/CommandLineTools, when a full regular Xcode was required (happens when CommandLineTools are installed after Xcode)"
Although his solution did not help me. I found that resetting the xcode-select path would and did it.
The solution that worked for me is to reset the path and so you dont have to re-install xcode. Run this line:
sudo xcode-select -r
Im also using MacOS, and the android package wasnt on the right path. This did it for me from terminal:
pico ~/.bash_profile
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export ANDROID_SDK_HOME=/Users/$USER/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/$USER/.android/avd
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_AVD_HOME
source ~/.bash_profile
----\
I was running 'tns run android --bundle' in visual code studio terminal or android studio terminal that continued to fail. So I run it from the terminal and executes android emulator successfully. Why is this? I am not sure yet.