Using Android Emulator from Windows in WMWare Fusion on a Mac – Xamarin

download.jpgYou can’t run Android in a VM so if you are running Windows on a Mac using VMWare Fusion, you’ll need to connect to the Android running on the Mac. More detail

Once you have installed Visual Studio for Mac, open it and run the emulator for Android.

On the Mac

Open a Terminal on your Mac and enter this to add the Android platform tools into the path:

echo ‘export PATH=$PATH:~/Library/Developer/Xamarin/android-sdk-macosx/platform-tools/’ >> ~/.bash_profile
source ~/.bash_profile
adb devices

If you get a permission error on the bash_profile, run this:

sudo chown YOURACCOUNTNAME ~/.bash_profile

You should see a nice list of the emulators running. That will show you that you have completed the first step. You do not need to ever run this again.

Screen Shot 2018-07-05 at 9.03.31 AM.png

Open TextEdit and add this as a text file:

#!/bin/bash
echo ‘Starting android pipe listener’
cd /tmp
mkfifo backpipe
nc -kl 5555 0<backpipe | nc 127.0.0.1 5555 > backpipe

In TextEdit go to the Format menu and choose Make Plain Text

In TexEdit save the file to your desktop but without the .txt extension. Note that we unchecked the .txt extension

Screen Shot 2018-07-05 at 9.20.27 AM.png

We now need to tell OSX that the file is an executable. Open Terminal and use the following command and path (yours will be a bit different than mine)

chmod 700 /Users/<your account>/Desktop/adb

Now we can run it by double clicking the adb file. This should will run in the background always. so many sure it’s run when you want to connect to Android from the Windows VM

Screen Shot 2018-07-05 at 10.41.07 AM.png

Screen Shot 2018-07-05 at 9.25.24 AM.png

On the PC

Now that you are running the bash script on the Mac, it’s ready to be connected to.

Add a Windows Batch file on your desktop there with the following. Run it one to have the connection set up. It will appear then disappear. If you loose connection, then run it again.

cd C:\Program Files (x86)\Android\android-sdk\platform-tools
adb.exe connect <IP address of the Mac, get it from the Mac Settings app-> network>

You’ll see the Android device in your Visual Studio:

Screen Shot 2018-07-05 at 11.05.24 AM.png

Enjoy!

Problems?

If when you use the adb devices command on the PC, you get an “unauthorized” go check the running android and ensure it isn’t asking for permission. If it is, grant it then run both script on the Mac and PC to re-establish connection.

Advertisements