How to run Viber on Visual Studio Emulator for Android

Introduction

Recently I needed set up Viber app for the phone number that is not used on smartphone. Obviously Viber could be installed as desktop app but it still requires app on mobile device for the same number. The same is true for WhatsApp and some other messengers.

The post is written for Svitla blog.

Scenario

Let’s consider Windows 10 (build 1803) with installed Hyper-V role. User needs Viber and WhatsApp applications and could be able to access emulated device. Also user is not a mobile developer so it is necessary just emulate mobile phone without digging too deep inside development stuff.

Scenario where user has no access to emulated device is considered in another post.

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 standalone application. Then required apps will be installed and emulator will be run by startup script.

Solution

Applications

Find and download apk files for required applications:

SDK tools

Emulator has its own device images, but requires adb.exe to install applications.

Download and extract Android command line tools to folder which path doesn’t include spaces, for example %ProgramData%\Android\sdk. By using sdkmanager install platform-tools:

"%ProgramData%\Android\sdk\tools\bin\sdkmanager" "platform-tools"

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:

%ProgramData%\Android\Sdk
%ProgramData%\Android\Sdk\platform-tools
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.

Application provides the list of preconfigured devices. Currently the latest API version that is used by 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 new virtual machine “VS Emulator 5.5-inch Marshmallow (6.0.0) XXHDPI Phone.admin”. It will be automatically run and stopped by emulator.

Run the device, and wait until it have 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.

Auto run

The last step is to start emulated device when user logs to session. It is necessary to find id of the installed device and add command file that run emulator.

A short note – when emulator is run from command line it fails to install new application. So you need run Visual Studio emulator for Android, launch emulated device, and then install 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 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 start.cmd file:

"%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 like 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.

Conclusions

Pros

  • Visual Studio emulator for Android works along with Hyper-V virtual machines;
  • Could be launched from command line;
  • Provide GUI and allows interaction with user.

Cons

  • 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».

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s