3
votes

I'm learning NativeScript and When running tns platform add android I receive the following error: I follow this step:

  1. Run the command prompt as an Administrator.
  2. @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
  3. choco install googlechrome -y
  4. choco install nodejs-lts -y
  5. choco install jdk8 -y
  6. choco install android-sdk -y
  7. "%ANDROID_HOME%\tools\bin\sdkmanager" "platform-tools" "platforms;android-25" "build-tools;25.0.2" "extras;android;m2repository" "extras;google;m2repository"
  8. @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://nativescript.org/setup/win-avd'))"
  9. choco install androidstudio -y
  10. npm i -g nativescript
  11. tns doctor I see "No issues were detected" you are good to go!
  12. tns create HelloWorld --template nativescript-template-tutorial
  13. cd HelloWorld
  14. tns run android

Error: Cannot find connected devices. Emulator start failed with: Cannot resolve the specified connected device by the provided index or identifier. To list currently connected devices and verify th at the specified index or identifier exists, run 'tns device'. To list currently connected devices and verify that the specified identifier exi sts, run 'tns device'. To list available emulator images, run 'tns device --available-device s'.

3
You would need either a real device connected or emulators installed on your PC. If you don't have a real device you can download and install system images for Android Virtual Devices (a.k.a. emulators) - developer.android.com/studio/run/managing-avds.html - Nick Iliev

3 Answers

3
votes

You can see all packages/images of the devices that you can download - avdmanager list. Choose the one you need and install:

cd $ANDROID_HOME/tools/bin

./sdkmanager "system-images;android-25;google_apis;x86"

./sdkmanager --licenses

And create the image:

avdmanager create avd -n test -k "system-images;android-25;google_apis;x86"

if you will get an error, as I got:

.android/repositories.cfg could not be loaded

run:

touch ~/.android/repositories.cfg

Now tns run android should work.

3
votes

First, make sure you are at $ANDROID_HOME\tools\bin (the default path is .\Android\android-sdk\tools\bin) in the command line.

Use the sdkmanager to install the package.

   sdkmanager “system-images;android-27;google_apis_playstore;x86”

To see the list of SDK packages use

sdkmanager --list

If you receive a "Package path is not valid. Valid system image paths are:ository" error, use:

sdkmanager --licenses

Then create the AVD by using

avdmanager create avd -n test -k "system-images;android-27;google_apis_playstore;x86"
1
votes

If you want to use real devices, you have to enable USB debugging in the developer options. After that, you can see the the application identifier as listed by tns device list-applications