11

is it possible to run react native app on Visual Studio Emulator for Android (standalone) and if yes what are the steps to set it up? I can successfully start emulator, that part works but cant figure out how to config react-native to use it instead of "adb devices".

My current attempts end with error: Could not debug. Error while executing command 'adb devices': Command failed: adb devices 'adb' is not recognized as an internal or external command, operable program or batch file.

I know about Android Studio and virtual devices that come with it but I would like to try that as the last option. My environment is: Windows 10 pro, VS Code (with React Native Tools Extension), react-native, yarn.

UPDATE

even though I did not get anywhere in my attempts to make it work I just would like to share what knowledge I gained while struggling with this issue because it is possible that my issues are specific to my environment but it might work on another PC.

Theoretically it requires very few steps to run react-native in Visual Studio Emulator for Android in VS code without installing Android Studio or Visual Studio.

  1. Install Visual Studio Emulator for Android, standalone https://www.visualstudio.com/vs/msft-android-emulator/

  2. download Android Debug Bridge (adb)

it is included with Android SDK Platform-Tools, download and read more here: https://developer.android.com/studio/command-line/adb.html it downloads as zip file, you unzip it and then add a path to adb.exe in PATH environment variable, so you can execute adb command from any path. I am using yarn and it needs that to know where adb.exe is.

It is kind of a connector between your app and virtual or real android device it has to be running before you start emulator and basic command are:

to stop - adb kill-server

to start - adb start-server

to see list of devices that adb recognized - adb devices

  1. I also found a specific instruction on how to make Visual Studio Emulator for Android work with adb:

https://msdn.microsoft.com/en-us/library/mt228282.aspx

'Visual Studio Emulator for Android' devices are not listed in the Android Device Monitor

it is a registry edit for key

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools

apparently Visual Studio Emulator for Android is using that and you can create it if it is not there and just add/modify Path variable to be a path to adb.exe.

  1. now you can start Visual Studio Emulator for Android and after that open integrated terminal in you react native VS code project and type:

yarn run android

and if I get it right (and in the perfect world) your app should get installed and shown in Visual Studio Emulator for Android, well, not for me, my emulator never shows up as a device when I type adb devices, all I see is a blank two lines.

So I think I spent enough time on this trying to make it work and in my case the answer to my own questions is:

theoretically you should be able to run Visual Studio Emulator for Android with react-native from VS code but in reality it probably will not work, so seek something more reliable.

I did see a little light at the end of the tunnel when I tried connecting my phone with USB using expo app, adb picked it up right away, "yarn run android" started doing something and expo even tried to load my app, I held my breath, my heart was racing, I was ready for a miracle... and .... boom... it just crashed, but this could be easier for me to resolve though, it appears some networking config issues, my phone does not recognize IP address which was in the output after running yarn and if this works,(big IF) then it is still good, I can run/debug react-native without using Android/Visual Studio.

Final update: could not make it work, stopped all attempts and went for Android Studio instead, Android Studio emulators work with react native and expo without any issues. (well, not yet, sample app runs OK at least.)

vlscanner
  • 448
  • 5
  • 16
  • in order for adb command to work see this https://stackoverflow.com/questions/20564514/adb-is-not-recognized-as-an-internal-or-external-command-operable-program-or – jay shah Mar 18 '18 at 05:38

2 Answers2

2

The same symptoms occurred to me when trying to set both React-Native and VS Emulator for Android together, and the following steps solved them:

  1. On the VS Emulator for Android, I checked my emulated phone's IP at the Tools/Network tab. Emulator Adapter #1 refers to the emulated phone.

  2. Then, I headed to the terminal and ran adb connect <ip_address>:5555. That made the emulated phone available to Android Studio as well as to React-Native.

Marcelo Cardoso
  • 251
  • 3
  • 10
1

if you already install android studio then add C:\Users\manu\AppData\Local\Android\Sdk\platform-tools path into environment path (replace your username instead of manu)

if you have not android studio then need download adb from https://github.com/intel/haxm/releases/download/v7.0.0/haxm-windows_v7_0_0.zip

then install

intelhaxm-android.exe

.

open a new terminal and now adb commnad will work

it is haxm source website https://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager-intel-haxm

Jevgeni Geurtsen
  • 3,133
  • 4
  • 17
  • 35
Man
  • 742
  • 1
  • 6
  • 23
  • thank you for your answer, would that help to use Visual Studio Emulator for Android with react-native ? – vlscanner Mar 22 '18 at 18:07
  • i am not use Visual Studio Emulator for Android. but if your device show in terminal after execute adb devices. if you use create-react-native app then works fine else you must need sdk then it should work properly – Man Mar 23 '18 at 01:51
  • I tried your suggestion, intel haxm setup requires turning off Hyper-V but Visual Studio Emulator for Android would not start when I disable it. Error message advises to ensure that Hyper-V is enabled. – vlscanner Mar 24 '18 at 01:54
  • it is installation guide https://software.intel.com/en-us/android/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-windows – Man Mar 24 '18 at 03:33