Nativescript project running with Visual Studio Em

2019-01-15 10:13发布

问题:

I have a Nativescript application that I'm developing using VS Code and have no issues when I try to run it using the Nativescript launch configurations from the Nativescript extension, when I'm using a real device connected with USB or when I use one of the android-sdk emulators.

Now I need to run Hyper-V on the machine too and those emulators cannot run when hypervisor is on. So I downloaded and installed Visual Studio Android Emulator which runs fine when I launch it manually.

Problem is that the nativescript project doesn't recognize this device either with tns device or adb devices commands and if I try to launch the application from VS Code it tries to launch one of the other emulators, which obviously fails due to the hypervisor/Intel Haax incompatibility.

Did any of you had this problem before and have any solutions you can share?

Thanks.

回答1:

Microsoft MSDN say :

If the emulator is running, but it does not appear to be connected to ADB or it does not appear in Android tools that make use of ADB (for example, Android Studio or Eclipse), you may need to adjust where the emulator looks for ADB.

The emulator uses a registry key to identify the base location of your Android SDK, and looks for the \platform-tools\adb.exe file under that directory.


Here We Go!! Step By Step ;)

Copy Your ANDROID SDK PATH for me it look like this :


To modify the Android SDK path used by the emulator:

  1. Open Registry Editor by selecting Run from the Start buttons context menu, typing regedit in the dialog box, and choosing OK.


  1. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Android SDK Tools in the folder tree on the left.

Note : if Android SDK Tools folder doesn't exist, Create it under WOW6432Node, And open it, And Create a String Value name it Path:)

  1. Modify the Path registry variable to match the path to your Android SDK.


  1. Restart the emulator and you should now be able to see the emulator connected to ADB and associated Android tools.


Now! Open Your Terminal (CMD), and Run ADB command

adb devices -l

YES YES !! The Visual Studio Emulator is running, and connected to ADB!


HERE WE GOO !!

Now We Want To Create A Demo App (for example FIRSTZAKI) ZAKI is my nickname :p

On Terminal (CMD) :

tns create FIRSTZAKI

Choose Android Platform

cd FIRSTZAKI\

tns platform add android

Check if VS EMULATOR is ready!

tns devices

YES YES ^^

Finally Step (RUN/BUILD) :

tns run android

WOW ... Great :)

AND .. Good Luck ♥ — ZAKI