If you've been looking for a way to develop your Xamarin Android apps in a Parallels Desktop Windows VM, but run the app in an Android emulator on your Mac, this post is an attempt to distill the information from across multiple sites to get you started.
- Xamarin Android Emulator Hosts File
- Xamarin Android Emulator Troubleshooting
- Xamarin Android Emulator Slow
- Xamarin Android Emulator Mac 2020
Many thanks to James Montemagno for pointing me to Paul Batum's post on the Xamarin forum.
Jun 22, 2018 In this article. The topics in this section explain how to install and configure Xamarin.Android to work with Visual Studio on Windows and macOS, how to use the Android SDK Manager to download and install Android SDK tools and components that are required for building and testing your app, how to configure the Android emulator for debugging, and how to connect a physical Android device to your. If you already have Visual Studio 2019, you can check for updates: Open Visual Studio for Mac. In the menu bar, select Visual Studio Check for Updates. Available updates will be displayed and select Update. Optional: Install Xcode. If you want to build Xamarin apps for iOS or macOS, you'll also need.
My Configuration
- Intel MBP running OS X Mavericks
- Parallels Desktop running a Windows 8 VM
Set up your Mac
1. Download & Install the Android SDK
Nothing can get done until the Android SDK is installed, so let's start there.
Install the Android SDK
You should end up with an SDK directory somewhere on your Mac with subdirectories like: extras, platform tools, tools, etc.
Yeah? -- Okay. Next.
2. Install the Intel HAXM
Intel HAXM - What?
Intel Hardware Accelerated Execution Manager. In short, it speeds up Android app emulation on Intel host machines. This step is necessary if you plan on creating custom AVDs that leverage the much faster Intel x86 images.
Xamarin Android Emulator Hosts File
Install the Intel OS X HAXM Zip
Do you use OS X Mavericks + Parallels Desktop 9 ?
Install the OS X 10.9 HAXM Hotfix
If you don't do this, when you launch an Intel x86 emulator image, your entire computer will freeze up forcing you to perform a hard reboot. No one wants that.
3. Configure your Mac for SSH sharing
In OS X Go To:
System Preferences > Sharing > Enable Remote Login
Leave the other options set to their defaults.
4. Start the Android emulator
Several AVDs came pre-configured when you installed the Android SDK. For the sake of this tutorial, we'll use one of those devices which use ARM images. To view the configured devices, start the AVD Manager:
Xamarin Android Emulator Troubleshooting
Open a command line
Navigate to the tools directory of your Android SDK: yourandroidsdkdirectory/tools
Enter the following command:
./android avd
The AVD Manager will open
Start an Android device:
- select a device with a green check
- press Start...
- the Launch Options dialog will appear. Press Launch
Earlier, we installed HAXM which allows the use of the Intel x86 images which run much faster than their ARM counterparts. If you'd like to try those out: open the SDK Manager, download the x86 images, then configure devices in the AVD Manager to use the x86 images instead of the ARM images.
Open a command line
Navigate to the tools directory of your Android SDK: yourandroidsdkdirectory/tools
Enter the following command:
./android
download the x86 images
edit a device in the AVD Manager to use an x86 image instead of an ARM image
5. Kill the ADB Server
Open a command line
Navigate to the platform-tools directory of your Android SDK: yourandroidsdkdirectory/platform-tools
Enter the following command:
./adb kill-server
Okay! -- Your Mac is ready.
Set up you Windows VM
1. Start your Windows VM in Parallels Desktop
2. Download and install PuTTY SSH Client
Install the PuTTY SSH Client
3. Create a new connection to your Mac
Let's connect to the Mac.
- Start PuTTY SSH Client
- Select Session from the Category panel on the left
- In the Host Name (or IP Address) field, enter the IP Address of you Mac (found at: System Preferences > Sharing)
- Leave the Port set to its default (should be 22)
- Make sure SSH is selected under Protocol
4. Configure port forwarding
Select Connection > SSH > Tunnels from the Category panel on the left side of the PuTTY SSH Client. From here add two forwarding configurations.
First
- Source Port: 5555
- Destination: localhost:5555
Second
Source Port: 5554
Destination: localhost:5554
Click on Open
You will be presented with a command line console. When prompted, enter your Mac admin username and password to open a connection from your Windows VM to OS X.
5. Kill then Start the ADB Server
Open a command line
Navigate to the platform-tools directory of your Android SDK: yourandroidsdkdirectory/platform-tools
Enter the following command:
adb.exe kill-server
Then enter the following command:
adb.exe start-server
Confirm that your Mac emulator device has been picked up by entering the following command:
adb.exe devices
You should see a device listed something like: emulator-5554
6. Open a Xamarin Android project
Now for the big test!
Xamarin Android Emulator Slow
Launch your Xamarin IDE of choice and open a Xamarin Android project. Once the project initializes, you should see your already running Mac emulator listed in the device dropdown.
And that's it! -- You can debug all day long from Parallels over to your Mac.
The Bonus Round - Genymotion Emulator
The AVD emulator that comes with the Android SDK is fine, but it could be better. Enter Genymotion.
The Genymotion emulator is noticably faster, but it requires some baggage: VirtualBox - which doesn't play well with Parallels Desktop 9 out of the box.
[Detailed tutorial coming soon]
When you are developing on an emulator, you may want to look at the files created by the application. Each emulator and SDK tools have different capabilities on reading and writing files to disk. You may want to do this to open a SQLite Database, or to change the hosts file in Windows Mobile Emulator.
Windows Mobile Emulator
Windows Mobile Emulator, I have found to be the most cumbersome. You must shutdown the emulator, and load the VDD separately to see what is stored locally.
Open up HyperV and ensure the image you want to open is stopped.
Xamarin Android Emulator Mac 2020
Next, go to the Settings for this Emulator, select the Hard Drive and copy the location of its Virtual Hard Disk.
Open Disk Management and select Action > Attach a VHD.
Copy the virtual hard disk’s location and press OK.
Locations
The hard drive will now be available for you to browse. The folder structure is very similar to a Windows installation.
Visual Studio Android Emulator
There are multiple ways to access vhd for Android. You can use the same method as above or you have two other options.
Install App
You can install a file explorer app on your Android device to browse through files. There are a lot to choose from, search File Explorer on Google Play Store on your emulator.
Android SDK Tools
Open the Android Device Monitor
From here you can select your emulator and open the files as needed in the File Explorer.
Locations
iOS Simulator
The iOS simulator runs on a Mac, even if you are building via Windows. IOS is much simplier to access than the others as it is just stored in a directory on the main disk drive.
First you will want to find your DeviceId. On your Mac, go to Hardware > Device > Manage Devices.
Then find your simulator and record the Device Identifier.
Now to get to your file location in iOS 8 and above, fill in the below. Regarding the ApplicationId, I normally look through a few folders until I find the right one.