How to run Viber on Visual Studio Emulator for Android
by Illya Reznykov
Recently I needed to set up a Viber app for the phone number that is not used on a smartphone. Obviously, Viber could be installed as a desktop app but it still requires an app on a mobile device for the same number. The same is true for WhatsApp and some other messengers.
Let’s consider Windows 10 (build 1803) with installed Hyper-V role. A user needs Viber and WhatsApp applications and could be able to access emulated device. Also, a user is not a mobile developer so it is necessary just emulate mobile phone without digging too deep inside development stuff.
As Android Studio emulator couldn’t be used along with Hyper-V role, Microsoft proposes to use Visual Studio emulator for Android that could be installed as a standalone application. Then required apps will be installed and the emulator will be run by a startup script.
Find and download apk files for required applications:
The emulator has its own device images but requires adb.exe to install applications.
In order to prevent “File transfer failed. Error: Unable to install the file through Adb. Adb.exe not found. Make sure you have Android SDK Tools installed” error until drag-and-drop apk file to emulated device window, you need update Path environment variable with the path to platform tools and merge the following reg file to the registry:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Android Studio] "Path"="C:\\Program Files\\Android\\Android Studio" "StartMenuGroup"="Android Studio" "SdkPath"="C:\\ProgramData\\Android\\Sdk" "UserSettingsPath"="C:\\Users\\Admin\\.android" "InstallSdk"="1" "InstallHaxm"="0"
Visual Studio emulator for Android
Download, install and run Visual Studio emulator for Android.
The application provides the list of pre-configured devices. Currently, the latest API version that is used by the proposed devices is API 23, so let’s choose 5.5" Marshmallow (6.0.0) XXHDPI Phone device. Click on the button to download device image, and wait until it is downloaded and installed. Hyper-V manager shows a new virtual machine “VS Emulator 5.5-inch Marshmallow (6.0.0) XXHDPI Phone.admin”. It will be automatically run and stopped by an emulator.
Run the device, and wait until it has been launched.
Drag downloaded apk files to device windows and wait until they have been installed. For this step mentioned above, platform tools are required.
Run Viber and WhatsApp, set your phone number and applications are ready to use.
The last step is to start an emulated device when a user logs to a session. It is necessary to find id of the installed device and add command file that runs emulator.
A short note – when the emulator is run from a command line it fails to install a new application. So you need to run Visual Studio emulator for Android, launch emulated device, and then install the required applications.
To run from command line, open the following file %ProgramFiles(x86)%\Microsoft Emulator Manager\1.0\Skus\Android\configurations.xml and search for the name of the installed image (for ex., “5.5” Marshmallow (6.0.0) XXHDPI Phone”):
<configuration id="4C0496D6-53F0-470C-9B20-CF0FD4DF71C4" type="device"> <settings type="plaintext"> configuration[id]=4C0496D6-53F0-470C-9B20-CF0FD4DF71C4 configuration.type=device configuration.version=1.0.60404.1 device.description=Similar to Motorola Moto X Play device.platform=5FB1F683-0D5B-496C-B12A-A74399055661 device.screen.diagonal=5.5 device.screen.resolution=1080x1920 device.vm.cpu.architecture=x86 device.vm.cpu.count=4 device.vm.heap.size=192 device.vm.ram.size=2048 device.vm.vhd=vhd\\5.5_Marshmallow_(6.0.0)_XXHDPI_Phone\\image.vhd device.name=5.5" Marshmallow (6.0.0) XXHDPI Phone </settings> <payload target="settings" type="plaintext"/> </configuration>
Then copy id from the first line and create
"%ProgramFiles(x86)%\Microsoft Emulator Manager\1.0\emulatorcmd" launch /sku:Android /id:4C0496D6-53F0-470C-9B20-CF0FD4DF71C4
This file could be added to
Startup folder as described in the article. It outputs the following:
C:\>"%ProgramFiles(x86)%\Microsoft Emulator Manager\1.0\emulatorcmd" launch /sku:Android /id:4C0496D6-53F0-470C-9B20-CF0FD4DF71C4 Validating emulator arguments... Determining if emulator is already running... Preparing virtual machine... Launching emulator... Emulator launched successfully.
- Visual Studio emulator for Android works along with Hyper-V virtual machines;
- Could be launched from a command line;
- Provide GUI and allows interaction with a user.
- A limited set of environments.
1. All used IP-addresses, names of servers, workstations, domains, are fictional and are used exclusively as a demonstration only.
2. Information is provided «AS IS».
Let's meet Svitla
We look forward to sharing our expertise, consulting you about your product idea, or helping you find the right solution for an existing project.
Your message is received. Svitla's sales manager of your region will contact you to discuss how we could be helpful.