nativescript-cli icon indicating copy to clipboard operation
nativescript-cli copied to clipboard

Android emulator not working

Open voigtd opened this issue 6 years ago • 10 comments
trafficstars

environment:

  • NativeScript: 5.3.4
  • Node: 10.15.3
  • MacOS Mojave: 10.14.3
  • Android Studio: 3.4

I'm getting an error when trying to open the android emulating by running tns run android --bundle. iOS is working fine. I initially installed via Homebrew (following the instructions from the docs), and then after that didn't work I installed the sdk via Android Studio and changed my ~/.bash_profile accordingly.

tns doctor says that everything should be working. Tried a lot of things to debug but haven't found a solution.

the error I get when I run tns run android --bundle is the following:

Skipping node_modules folder! Use the syncAllFiles option to sync files from this folder.
Searching for devices...
Cannot find connected devices.
Emulator start failed with: No emulator image available for device identifier 'undefined'.
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'.

When I run tns device android --available-devices it shows installed devices while simultaneously saying that devices weren't found:

Available emulators
┌─────────────┬──────────┬───────────┬───────────────────┬──────────────────┬────────────┐
│ Device Name │ Platform │ Version   │ Device Identifier │ Image Identifier │ Error Help │
│ Pixel2      │ Android  │           │                   │ Pixel2           │            │
└─────────────┴──────────┴───────────┴───────────────────┴──────────────────┴────────────┘

Connected devices & emulators
Searching for devices...
Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again.

When I run tns run android --log trace I get the following error:

Loading extensions.
Asserting extension nativescript-cloud is installed.
Extension nativescript-cloud is installed.
Trying to get macOS version.
Exec system_profiler SPSoftwareDataType -detailLevel mini
 stdout: Software:

    System Software Overview:

      System Version: macOS 10.14.3 (18D42)
      Kernel Version: Darwin 18.2.0
      Time since boot: 4:19


 stderr:
macOS version based on system_profiler is 10.14.
Looking for project in '/Users/daniel/Desktop/ng-ns-demo'
Project directory is '/Users/daniel/Desktop/ng-ns-demo'.
System information:
[Object: null prototype] {
  platform: 'darwin',
  shell: '/bin/bash',
  os:
   'Darwin Daniels-Mac 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64\n',
  procArch: 'x64',
  nodeVer: '10.15.3',
  npmVer: '6.4.1',
  nodeGypVer: null,
  nativeScriptCliVersion: '5.3.4',
  gitVer: '2.18.0',
  dotNetVer: null,
  javacVersion: '1.8.0_212',
  javaVersion: '1.8.0_212',
  adbVer: '1.0.41',
  androidInstalled: true,
  monoVer: null,
  gradleVer: null,
  isAndroidSdkConfiguredCorrectly: true,
  xcodeVer: '10.2.1',
  xcodeprojLocation: '/usr/local/bin/xcodeproj',
  itunesInstalled: true,
  cocoaPodsVer: '1.6.1',
  isCocoaPodsWorkingCorrectly: true,
  isCocoaPodsUpdateRequired: false,
  pythonInfo: { isInstalled: true, isSixPackageInstalled: true } }
Initializing analytics statuses.
Analytics statuses:  { TrackFeatureUsage: 'disabled', TrackExceptions: 'disabled' }
Your ANDROID_HOME environment variable is set and points to correct directory.
Your adb from the Android SDK is correctly installed.
The Android SDK is installed.
A compatible Android SDK for compilation is found.
Javac is installed and is configured properly.
The Java Development Kit (JDK) is installed and is configured properly.
Installed Android Targets are:  [ 'android-28' ]
Directories found in /Users/daniel/Library/Android/sdk/build-tools are 28.0.3
Versions found in /Users/daniel/Library/Android/sdk/build-tools are 28.0.3
Selected version is:  28.0.3
Selected targetSdk is: 28
Validate options for platform: Android
Skipping node_modules folder! Use the syncAllFiles option to sync files from this folder.
Searching for devices...
startLookingForDevices; platform is Android
Options for ios-device-discovery { platform: 'Android',
  shouldReturnImmediateResult: false,
  emulator: false }
spawn: /Users/daniel/Library/Android/sdk/platform-tools/adb "start-server"
Result when throw error is false:
{ stdout: '', stderr: '', exitCode: 0 }
spawn: /Users/daniel/Library/Android/sdk/platform-tools/adb "devices"
spawn: /Users/daniel/Library/Android/sdk/platform-tools/adb "devices"
spawn: /Users/daniel/Library/Android/sdk/tools/bin/avdmanager "list" "avds"
spawn: /usr/local/bin/VBoxManage "list" "vms"
spawn: player 0
Configuration error for Genymotion { stdout: '', stderr: 'spawn player ENOENT', exitCode: 'ENOENT' }
spawn: /usr/local/bin/VBoxManage "guestproperty" "enumerate" "e58dcf62-74df-43eb-858a-07faa6606f14"
No emulator image available for device identifier 'undefined'.
Cannot find connected devices.
Emulator start failed with: No emulator image available for device identifier 'undefined'.
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'.
Error while initializing devicesService: Exception: Cannot find connected devices.
Emulator start failed with: No emulator image available for device identifier 'undefined'.
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'.
Error: Cannot find connected devices.
Emulator start failed with: No emulator image available for device identifier 'undefined'.
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'.
    at Errors.fail (/usr/local/lib/node_modules/nativescript/lib/common/errors.js:126:28)
    at Errors.failWithoutHelp (/usr/local/lib/node_modules/nativescript/lib/common/errors.js:136:21)
    at DevicesService.<anonymous> (/usr/local/lib/node_modules/nativescript/lib/common/mobile/mobile-core/devices-service.js:445:34)
    at Generator.throw (<anonymous>)
    at rejected (/usr/local/lib/node_modules/nativescript/lib/common/mobile/mobile-core/devices-service.js:11:65)
    at process._tickCallback (internal/process/next_tick.js:68:7)

My ~/.bash_profile file currently is the following:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
export ANDROID_HOME=/Users/daniel/Library/Android/sdk
export ANDROID_SDK_ROOT=/Users/daniel/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/daniel/Library/Android/sdk/.android/avd

Also, I'm getting the following error after running: /Users/daniel/Library/Android/sdk/tools/bin/avdmanager list avd:

The following Android Virtual Devices could not be loaded:
    Name: Pixel2
    Path: /Users/daniel/.android/avd/Pixel2.avd
   Error: Google pixel_2 no longer exists as a device

voigtd avatar May 08 '19 11:05 voigtd

Hi @voigtd , It seem that the Pixel2 avd is corrupted - Error: Google pixel_2 no longer exists as a device. You can try to remove it with /Users/daniel/Library/Android/sdk/tools/bin/avdmanager delete avd -n "Pixel2". Then create a new avd using the Android Studio UI following Android Studio User Guide.

KristianDD avatar May 08 '19 15:05 KristianDD

Hi @KristianDD, thanks for looking at this.

Here's an update to anyone that has this problem. I see it happening to a bunch of people as I've been looking through issues and I was able to reproduce it on another mac of mine after going through the default NativeScript and Android Studio installations:

When you are installing the Android Studio desktop app you need to choose to do a custom installation versus their default installation. When you choose the custom installation you have an option to install the AVD package as well as the sdk. Make sure to check that box. The AVD package is what you need to get your Android emulator working. If you do the default installation it does not install the AVD package and even if you install it separately it won't be linked to your Android Studio installation unless further configured. So that's why the 'device not found' errors will pop up when you install NativeScript and Android Studio using the default settings.

Also if you are going the Android Studio installation route make sure that your ~/.bash_profile file is linked to your Android Studio installation and not the default Homebrew installation that NativeScript will give you.

i.e.

export ANDROID_HOME=/Users/daniel/Library/Android/sdk
export ANDROID_SDK_ROOT=/Users/daniel/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/daniel/Library/Android/sdk/.android/avd

Another thing - if your current Android Studio config isn't working you need to completely uninstall it from your Mac and reinstall it the way mentioned above. https://stackoverflow.com/questions/17625622/how-to-completely-uninstall-android-studio-on-mac

Changing the above got the Android emulator working nicely with NativeScript on both of the macs I tested this with.

voigtd avatar May 08 '19 20:05 voigtd

Hey @voigtd , I think you should consider re-opening this issue. All this stuff is supposed to be handled by {NS}.

paxperscientiam avatar May 19 '19 19:05 paxperscientiam

@paxperscientiam re-opened

voigtd avatar May 20 '19 13:05 voigtd

Same issue here. I already have Android Studio installed and I'm a Android developer. My emulators are ok when developing on Android Studio - everything works fine. My Android Studio is already fully configured and it works well developing native Android apps. But I know nothing on iOS development and I'm starting NativeScript. But can't see a sample project running on Android emulator.

What I have done: 1 - download and installed NativeScript (and it's CLI) and Vue 2 - tns create PROJECT_NAME --template vue 3 - tns run android

The terminal answer was:

Searching for devices...
Starting Android emulator with image Pixel_2_API_27
Waiting for emulator device initialization...
Unable to find applicable devices to execute operation. Ensure connected devices are trusted and try again.

The command tns run android opens a terminal that opens an the Pixel_2 emulator, but it does not run the project on it.

Running tns doctor everything is fine:

No issues were detected.
Your ANDROID_HOME environment variable is set and points to correct directory.
Your adb from the Android SDK is correctly installed.
The Android SDK is installed.
A compatible Android SDK for compilation is found.
Javac is installed and is configured properly.
The Java Development Kit (JDK) is installed and is configured properly.
Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.
Component nativescript has 6.5.0 version and is up to date.
Component tns-core-modules has 6.5.1 version and is up to date.
Component tns-android has 6.5.0 version and is up to date.
Component tns-ios has 6.5.0 version and is up to date.

Running tns devices android --available-devicess it shows the device installed but none connected even with the emulator open: tns devices android --available-devices result

I'm on Windows 10. My tns version is 6.5.0.

gabrielfgularte avatar May 15 '20 17:05 gabrielfgularte

Getting the same issue. Was working before but not now.

basickarl avatar Oct 22 '20 12:10 basickarl

  1. Have you tried rebooting your computer, On know on my computer some OS updates frequently causes the emulator to fail to actually start until after I do a restart.
  2. Can you do a tns devices android --log trace and post the log here; it will probably point out what is failing.

NathanaelA avatar Oct 22 '20 15:10 NathanaelA

@nadyaA I did get it working eventually. I updated the SDK in Android Studio and I did not use the API version R. I used explicitly the API version 30 (I made a new emulator). I don't think NativeScript can handle R as a version number?

image

basickarl avatar Oct 22 '20 17:10 basickarl

Changing Android version from 11 to 10 helped!

amartyna avatar Dec 10 '20 13:12 amartyna

Does not work for me either, with API 30 emulator. I can successfully run Android apps from within Android Studio though.

$ ns run android
Searching for devices...
Starting Android emulator with image Pixel_4_API_30
Waiting for emulator device initialization...
Unable to find applicable devices to execute operation. Ensure connected devices are trusted and try again.
$ ns run android
Searching for devices...
Starting Android emulator with image Pixel_4_API_30
Waiting for emulator device initialization...
Cannot find connected devices.
Emulator start failed with: The "path" argument must be of type string. Received undefined
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'.
$ adb devices
List of devices attached
emulator-5554   device

OS: Windows

$ ns doctor android
- Getting environment information

✔ Getting environment information

No issues were detected.
Your ANDROID_HOME environment variable is set and points to correct directory.
Your adb from the Android SDK is correctly installed.
The Android SDK is installed.
A compatible Android SDK for compilation is found.
Javac is installed and is configured properly.
The Java Development Kit (JDK) is installed and is configured properly.
Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.
✔ Your ANDROID_HOME environment variable is set and points to correct directory.
✔ Your adb from the Android SDK is correctly installed.
✔ The Android SDK is installed.
✔ A compatible Android SDK for compilation is found.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.
- Getting NativeScript components versions information...
✔ Getting NativeScript components versions information...
Component nativescript has 8.1.4 version and is up to date.
Update available for component @nativescript/core. Your current version is 8.1.4 and the latest available version is 8.1.5.
Component @nativescript/android has 8.1.1 version and is up to date.
✔ Component nativescript has 8.1.4 version and is up to date.
⚠ Update available for component @nativescript/core. Your current version is 8.1.4 and the latest available version is 8.1.5.
✔ Component @nativescript/android has 8.1.1 version and is up to date.

sryze avatar Nov 03 '21 06:11 sryze