Skip to content

tns run android (without started emulator/connected device) fails to start app #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NickIliev opened this issue Feb 3, 2017 · 14 comments

Comments

@NickIliev
Copy link
Contributor

On Windows with Node.js 6.9.5 and NativeScript CLI 2.5.0
Steps to reproduce:

  • close all emulators and de-attach all connected devices
  • run this angular app
  • the CLI starts the default emulator - the emulator start successfully but the CLI never continues the execution of the build.

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
@KristiyanFxy
Copy link

KristiyanFxy commented Jan 3, 2018

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,

@Plamen5kov
Copy link
Contributor

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.

@KristiyanFxy
Copy link

KristiyanFxy commented Jan 3, 2018

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.
resource-manager

To reproduce the problem I follow the steps found here: https://docs.nativescript.org/angular/tutorial/ng-chapter-1

  1. tns create [gameName]--template nativescript-template-ng-tutorial
  2. cd [gameName]
  3. tns run android
  4. @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://www.nativescript.org/setup/win'))"
  5. profit!

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:\Android\android-sdk\platform-tools\adb "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:\Android\android-sdk\platform-tools\adb" version
stdout: Android Debug Bridge version 1.0.39
Version 0.0.1-4500957
Installed as C:\Android\android-sdk\platform-tools\adb.exe

stderr:
spawn: C:\Android\android-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

search for system disk images in \r\n -system read initial system image from \r\n -writable-system make system image writable after 'adb remount'\r\n -datadir write user data into \r\n -kernel use specific emulated kernel\r\n -ramdisk ramdisk image (default /ramdisk.img\r\n -image obsolete, use -system instead\r\n -initdata same as '-init-data '\r\n -data data image (default /userdata-qemu.img\r\n -partition-size system/data partition size in MBs\r\n -cache cache partition image (default is temporary file)\r\n -cache-size cache partition size in MBs\r\n -no-cache disable the cache partition\r\n -nocache same as -no-cache\r\n -sdcard SD card image (default /sdcard.img\r\n -snapstorage file that contains all state snapshots (default /snapshots.img)\r\n -no-snapstorage do not mount a snapshot storage file (this disables all snapshot functionality)\r\n -snapshot name of snapshot within storage file for auto-start and auto-save (default 'default-boot')\r\n -no-snapshot perform a full boot and do not do not auto-save, but qemu vmload and vmsave operate on snapstorage\r\n -no-snapshot-save do not auto-save to snapshot on exit: abandon changed state\r\n -no-snapshot-load do not auto-start from snapshot: perform a full boot\r\n -snapshot-list show a list of available snapshots\r\n -no-snapshot-update-time do not do try to correct snapshot time on restore\r\n -wipe-data reset the user data image (copy it from initdata)\r\n -avd use a specific android virtual device\r\n -skindir search skins in (default /skins)\r\n -skin select a given skin\r\n -no-skin deprecated: create an AVD with no skin instead\r\n -noskin same as -no-skin\r\n -memory physical RAM size in MBs\r\n -accel Configure emulation acceleration\r\n -no-accel Same as '-accel off'\r\n -ranchu Use new emulator backend instead of the classic one\r\n -engine Select engine. auto|classic|qemu2\r\n -netspeed maximum network download/upload speeds\r\n -netdelay network latency emulation\r\n -netfast disable network shaping\r\n -code-profile enable code profiling\r\n -show-kernel display kernel messages\r\n -shell enable root shell on current terminal\r\n -no-jni disable JNI checks in the Dalvik runtime\r\n -nojni same as -no-jni\r\n -logcat enable logcat output with given tags\r\n -no-audio disable audio support\r\n -noaudio same as -no-audio\r\n -audio use specific audio backend\r\n -raw-keys disable Unicode keyboard reverse-mapping (deprecated)\r\n -radio redirect radio modem interface to character device\r\n -port TCP port that will be used for the console\r\n -ports , TCP ports used for the console and adb bridge\r\n -onion

use overlay PNG image over screen\r\n -onion-alpha <%age> specify onion-skin translucency\r\n -onion-rotation 0|1|2|3 specify onion-skin rotation\r\n -dpi-device specify device's resolution in dpi (default 165)\r\n -scale scale emulator window (deprecated)\r\n -http-proxy make TCP connections through a HTTP/HTTPS proxy\r\n -timezone use this timezone instead of the host's default\r\n -dns-server use this DNS server(s) in the emulated system\r\n -cpu-delay throttle CPU emulation\r\n -no-boot-anim disable animation for faster boot\r\n -no-window disable graphical window display\r\n -version display emulator version number\r\n -report-console report console port to remote socket\r\n -gps redirect NMEA GPS to character device\r\n -keyset specify keyset file name\r\n -shell-serial specific character device for root shell\r\n -tcpdump capture network packets to file\r\n -bootchart enable bootcharting\r\n -charmap use specific key character map\r\n -prop = set system property on boot\r\n -shared-net-id join the shared network, using IP address 10.1.2.\r\n -gpu set hardware OpenGLES emulation mode\r\n -camera-back set emulation mode for a camera facing back\r\n -camera-front set emulation mode for a camera facing front\r\n -webcam-list lists web cameras available for emulation\r\n -screen set emulated screen mode\r\n -force-32bit always use 32-bit emulator\r\n -selinux <disabled|permissive> Set SELinux to either disabled or permissive mode\r\n -unix-pipe Add to the list of allowed Unix pipes\r\n -fixed-scale Use fixed 1:1 scale for the initial emulator window.\r\n\r\n -qemu args... pass arguments to qemu\r\n -qemu -h display qemu help\r\n\r\n -verbose same as '-debug-init'\r\n -debug enable/disable debug messages\r\n -debug- enable specific debug messages\r\n -debug-no- disable specific debug messages\r\n\r\n -help print this help\r\n -help- print option-specific help\r\n\r\n -help-disk-images about disk images\r\n -help-keys supported key bindings\r\n -help-debug-tags debug tags for -debug \r\n -help-char-devices character specification\r\n -help-environment environment variables\r\n -help-keyset-file key bindings configuration file\r\n -help-virtual-device virtual device management\r\n -help-sdk-images about disk images when using the SDK\r\n -help-build-images about disk images when building Android\r\n -help-all prints all help content\r\n\r\n',
stderr: '',
exitCode: 1 }
The result of checking is Android Emulator installed is:

  • stdout: Android Emulator usage: emulator [options] [-qemu args]
    options:
    -list-avds list available AVDs
    -sysdir

    search for system disk images in
    -system read initial system image from
    -writable-system make system image writable after 'adb remount'
    -datadir write user data into
    -kernel use specific emulated kernel
    -ramdisk ramdisk image (default /ramdisk.img
    -image obsolete, use -system instead
    -initdata same as '-init-data '
    -data data image (default /userdata-qemu.img
    -partition-size system/data partition size in MBs
    -cache cache partition image (default is temporary file)
    -cache-size cache partition size in MBs
    -no-cache disable the cache partition
    -nocache same as -no-cache
    -sdcard SD card image (default /sdcard.img
    -snapstorage file that contains all state snapshots (default /snapshots.img)
    -no-snapstorage do not mount a snapshot storage file (this disables all snapshot functionality)
    -snapshot name of snapshot within storage file for auto-start and auto-save (default 'default-boot')
    -no-snapshot perform a full boot and do not do not auto-save, but qemu vmload and vmsave operate on snapstorage
    -no-snapshot-save do not auto-save to snapshot on exit: abandon changed state
    -no-snapshot-load do not auto-start from snapshot: perform a full boot
    -snapshot-list show a list of available snapshots
    -no-snapshot-update-time do not do try to correct snapshot time on restore
    -wipe-data reset the user data image (copy it from initdata)
    -avd use a specific android virtual device
    -skindir search skins in (default /skins)
    -skin select a given skin
    -no-skin deprecated: create an AVD with no skin instead
    -noskin same as -no-skin
    -memory physical RAM size in MBs
    -accel Configure emulation acceleration
    -no-accel Same as '-accel off'
    -ranchu Use new emulator backend instead of the classic one
    -engine Select engine. auto|classic|qemu2
    -netspeed maximum network download/upload speeds
    -netdelay network latency emulation
    -netfast disable network shaping
    -code-profile enable code profiling
    -show-kernel display kernel messages
    -shell enable root shell on current terminal
    -no-jni disable JNI checks in the Dalvik runtime
    -nojni same as -no-jni
    -logcat enable logcat output with given tags
    -no-audio disable audio support
    -noaudio same as -no-audio
    -audio use specific audio backend
    -raw-keys disable Unicode keyboard reverse-mapping (deprecated)
    -radio redirect radio modem interface to character device
    -port TCP port that will be used for the console
    -ports , TCP ports used for the console and adb bridge
    -onion use overlay PNG image over screen
    -onion-alpha <%age> specify onion-skin translucency
    -onion-rotation 0|1|2|3 specify onion-skin rotation
    -dpi-device specify device's resolution in dpi (default 165)
    -scale scale emulator window (deprecated)
    -http-proxy make TCP connections through a HTTP/HTTPS proxy
    -timezone use this timezone instead of the host's default
    -dns-server use this DNS server(s) in the emulated system
    -cpu-delay throttle CPU emulation
    -no-boot-anim disable animation for faster boot
    -no-window disable graphical window display
    -version display emulator version number
    -report-console report console port to remote socket
    -gps redirect NMEA GPS to character device
    -keyset specify keyset file name
    -shell-serial specific character device for root shell
    -tcpdump capture network packets to file
    -bootchart enable bootcharting
    -charmap use specific key character map
    -prop = set system property on boot
    -shared-net-id join the shared network, using IP address 10.1.2.
    -gpu set hardware OpenGLES emulation mode
    -camera-back set emulation mode for a camera facing back
    -camera-front set emulation mode for a camera facing front
    -webcam-list lists web cameras available for emulation
    -screen set emulated screen mode
    -force-32bit always use 32-bit emulator
    -selinux <disabled|permissive> Set SELinux to either disabled or permissive mode
    -unix-pipe Add to the list of allowed Unix pipes
    -fixed-scale Use fixed 1:1 scale for the initial emulator window.

    -qemu args... pass arguments to qemu
    -qemu -h display qemu help

    -verbose same as '-debug-init'
    -debug enable/disable debug messages
    -debug- enable specific debug messages
    -debug-no- disable specific debug messages

    -help print this help
    -help- print option-specific help

    -help-disk-images about disk images
    -help-keys supported key bindings
    -help-debug-tags debug tags for -debug
    -help-char-devices character specification
    -help-environment environment variables
    -help-keyset-file key bindings configuration file
    -help-virtual-device virtual device management
    -help-sdk-images about disk images when using the SDK
    -help-build-images about disk images when building Android
    -help-all prints all help content

  • stderr:
    Exec mono --version
    stdout:
    stderr: 'mono' is not recognized as an internal or external command,
    operable program or batch file.

Error while executing mono --version: Command failed: mono --version
'mono' is not recognized as an internal or external command,
operable program or batch file.

Exec git --version
stdout: git version 2.9.2.windows.1

stderr:
Exec gradle -v
stdout:
stderr: 'gradle' is not recognized as an internal or external command,
operable program or batch file.

Error while executing gradle -v: Command failed: gradle -v
'gradle' is not recognized as an internal or external command,
operable program or batch file.

Exec "C:\Program Files\Java\jdk1.8.0_152\bin\javac" -version
stdout:
stderr: javac 1.8.0_152

System information:
{ procInfo: 'nativescript/3.4.0',
platform: 'win32',
os: 'Windows 10 Pro 6.3.16299',
shell: 'C:\WINDOWS\system32\cmd.exe',
dotNetVer: '4.7.02556',
procArch: 'x64',
nodeVer: 'v6.9.5',
npmVer: '5.6.0',
javaVer: '1.8.0',
nodeGypVer: null,
xcodeVer: null,
xcodeprojGemLocation: null,
itunesInstalled: false,
cocoapodVer: null,
adbVer: 'Android Debug Bridge version 1.0.39',
emulatorInstalled: true,
monoVer: null,
gitVer: '2.9.2.windows.1',
gradleVer: null,
javacVersion: '1.8.0_152' }
Starting watch on killswitch C:\Users\KRISTI~1\AppData\Local\Temp\kristiyan\KillSwitches\cli
Looking for project in 'Z:\Work\Work 2018\Associations-Game_repository\Associations-game'
Project directory is 'Z:\Work\Work 2018\Associations-Game_repository\Associations-game'.
Installed Android Targets are: [ 'android-25' ]
Directories found in C:\Android\android-sdk\build-tools are 25.0.2
Versions found in C:\Android\android-sdk\build-tools are 25.0.2
Selected version is: 25.0.2
Selected targetSdk is: 25
Directories found in C:\Android\android-sdk\extras\android\m2repository\com\android\support\appcompat-v7 are 18.0.0, 19.0.0, 19.0.1, 19.1.0, 20.0.0, 21.0.0, 21.0.2, 21.0.3, 22.0.0, 22.1.0, 22.1.1, 22.2.0, 22.2.1, 23.0.0, 23.0.1, 23.1.0, 23.1.1, 23.2.0, 23.2.1, 23.3.0, 23.4.0, 24.0.0, 24.0.0-alpha1, 24.0.0-alpha2, 24.0.0-beta1, 24.1.0, 24.1.1, 24.2.0, 24.2.1, 25.0.0, 25.0.1, 25.1.0, 25.1.1, 25.2.0, 25.3.0, 25.3.1, 26.0.0-alpha1, maven-metadata.xml, maven-metadata.xml.md5, maven-metadata.xml.sha1
Versions found in C:\Android\android-sdk\extras\android\m2repository\com\android\support\appcompat-v7 are 18.0.0, 19.0.0, 19.0.1, 19.1.0, 20.0.0, 21.0.0, 21.0.2, 21.0.3, 22.0.0, 22.1.0, 22.1.1, 22.2.0, 22.2.1, 23.0.0, 23.0.1, 23.1.0, 23.1.1, 23.2.0, 23.2.1, 23.3.0, 23.4.0, 24.0.0, 24.0.0, 24.0.0, 24.0.0, 24.1.0, 24.1.1, 24.2.0, 24.2.1, 25.0.0, 25.0.1, 25.1.0, 25.1.1, 25.2.0, 25.3.0, 25.3.1, 26.0.0
Selected version is: 25.3.1
Selected AppCompat version is: 25.3.1
Validate options for platform: Android
Initializing analytics statuses.
Analytics statuses: { TrackFeatureUsage: 'disabled', TrackExceptions: 'disabled' }
Searching for devices...
startLookingForDevices; platform is Android
execFile: C:\Android\android-sdk\platform-tools\adb "help"
spawn: C:\Android\android-sdk\platform-tools\adb "start-server"
Result when throw error is false:
{ stdout: '', stderr: '', exitCode: 0 }
spawn: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
Starting Android emulator with image Xamarin_Android_API_23
spawn: C:\Android\android-sdk\tools\emulator "-avd" "Xamarin_Android_API_23"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
execFile: C:\Android\android-sdk\platform-tools\adb "devices"
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.
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'.
Error: 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'.
at Object. (C:\Users\kristiyan\AppData\Roaming\npm\node_modules\nativescript\lib\common\errors.js:16:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (C:\Users\kristiyan\AppData\Roaming\npm\node_modules\nativescript\lib\nativescript-cli.js:15:18)
at Module._compile (module.js:570:32)

Z:\Work\Work 2018\Associations-Game_repository\Associations-game>

@Plamen5kov
Copy link
Contributor

Plamen5kov commented Jan 4, 2018

@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

@Plamen5kov Plamen5kov reopened this Jan 4, 2018
@KristiyanFxy
Copy link

KristiyanFxy commented Jan 4, 2018

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:

  1. Black screen when running AVD emulator.
  2. AVD android emulator is laggy when running.
  3. tns doctor not finding any problems but tns run android --timeout 300 times out with error.
  4. Command gradlew.bat failed with exit code 1.
  5. tns run android throws Java (javac) error.

1. Black screen when running AVD emulator

Problem & Suspected reason

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.

Fix

  1. Run AVD Manager as Administrator
  2. Click on the Tools > Manage SDK...
  3. Make sure you have all API version 23 (at least I went for 23) mobile packets > Install the once you don't have.
  4. Download and install Intel HAXM (Link to Intel official site: here).
    Note: You will notice HAXM is an actual option in AVD SDK Manager but it reads "Not Compatible with Windows"... dont worry, just download the executable from Intel's official website.
    haxm_not_compatible

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"

haxm_problem

  1. After SDK and HAXM are download and installed, restart AVD Manager (again in Administrator mode).
  2. Delete all Android Virtual devices (I did that because TNS will always target the highest available Android version & removed any confusion for further debugging).
  3. In the "Device Definitions" tab > find "Nexus 7" > click on "Create AVD"

avd emulator

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.
8. Click on Ok > Start...
9. Profit!

2. AVD Android emulator is laggy when running

Problem & Suspected reason

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.

Fix

  1. Run AVD Manager as Administrator
  2. Click on your AVD device > Edit...
  3. Enable "Use Host GPU" (also shown on the picture above)
  4. Click "OK" > Start...
  5. Profit!

3. tns doctor not finding any problems but tns run android --timeout 300 times out with error.

Problem & Suspected reason

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."
image
That being said, after using the workaround mentioned bellow, tns finds the emulator.
image

Fix... Workaround

  1. Run AVD Manager as Administrator
  2. Run your Emulated Android device
  3. Open CMD/PS/Bash... as Administrator > CD [project directory] > tns run android --timeout 100

Note: 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.
build_error
4. Profit!
image

4. Command gradlew.bat failed with exit code 1.

Problem & Suspected reason

As explained by @Plamen5kov in ticket #2092 the problem is due to conflicting jars.

Fix

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

  1. Open package.json
  2. Delete "tns-android": "^2.2.0" from Dependencies
  3. Delete node_modules and the platforms directories
  4. tns run android
  5. Profit!

5. tns run android throws Java (javac) error.

## Problem & Suspected reason

This was caused by the installer skipping jdk8 installation because I already had it installed, unfortunately, the current installation was causing problems.

Fix

You will need to force install jdk8

  1. Run CMD/Bash/PS... as Administrator
  2. choco install jdk8 -y
    Note: If you already have JDK installed, you might need to use the --force reserve word
  3. tns run android
  4. Profit!

Conclusion

The problem is with the development environment, that being said I hope my comment will help in the future others.

image

Cheers,

@Plamen5kov
Copy link
Contributor

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

@jmfederico
Copy link

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.

@yashwp
Copy link

yashwp commented Sep 25, 2018

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

screenshot 53

mbektchiev added a commit to NativeScript/docs-v7 that referenced this issue Dec 18, 2018
The quoted section from NativeScript/nativescript-cli#2486
is redundant and can fall off sync. It also makes the whole article rather messy
and difficult to read.
@IamGiel
Copy link

IamGiel commented Feb 22, 2019

@yashwp did you find the solution? I have the same outcome.

@mesterm
Copy link

mesterm commented Feb 23, 2019

@yashwp Same here :(

@IamGiel
Copy link

IamGiel commented Feb 23, 2019

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.

@yashwp
Copy link

yashwp commented Feb 27, 2019

@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

@LeCoupa
Copy link

LeCoupa commented Mar 11, 2019

Thank you @IamGiel. I was also using VSCode and tns run android --bundle kept failing again and again... Until I updated the variables 🤞

@ChrisMyrick
Copy link

ChrisMyrick commented Aug 7, 2019

You will also receive this error if emulator.exe does not exist here:
C:\Android\android-sdk\emulator\emulator.exe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants