Microsoft just announced the release of the first preview of the Surface Duo Emulator and SDK. Let's see how to get it running, so we can start building the first awesome dual-screen Xamarin.Android apps! From the Docs home page for dual-screen development we click on the Get the Surface Duo SDK Preview link:
This leads us to Download Center with a big red Download button, which we click, and the beefy (around 800 MB) download should start.
Installation
Ensure you have Visual Studio with Xamarin workload installed (native development with Android Studio is supported as well, see docs). Make sure to update to the latest stable versions of the Android SDKs and especially the Android Emulator. You can do this by going to the Android SDK Manager in Visual Studio.
Unzip the downloaded .zip
file and double-click the .exe
installer. The installation takes a while, so sit back and relax.
Launch the emulator
When the installation finishes, we can find the Emulator among installed apps. Press the Windows key and start typing Surface Duo Emulator. The launcher app should pop up among the best matches. After opening, a console window will pop up and configure the emulator for launch.
If you encounter any problems, open the launcher .bat
file from command line (you should find it in C:\Users\USERNAME\SurfaceDuoEmulator\artifacts\run.bat
) and pay attention to the error messages. In my case, the Hyper-V/Windows Hypervisor Platform were not running properly, and I had to manually turn them off (using Turn Windows Features On/Off control panel), restart PC and turn back on.
Using emulator from Visual Studio
Of course, the Emulator becomes even more awesome when we run our app on it! At first, I was a bit confused about how to do this, but the instructions for Xamarin developers are at the very bottom of the Use the Surface Duo emulator docs page. Close the emulator and go to the C:\Users\USERNAME\SurfaceDuoEmulator\artifacts\
folder. Make a backup copy of the run.bat
file. Open the run.bat
file in your favorite text editor and replace its contents with the following:
As the contents of the script say, ensure the ANDROID_SDK_LOCATION
is set correctly to the location of Visual Studio Android SDK. We can launch Visual Studio and rerun the emulator. When you select a Xamarin.Android project as the Startup project, you should see the Surface Duo Emulator listed among the running devices.
In my case I had to restart the emulator again to make it appear successfully. Note its name will be <build> (Android 10.0 - API 29). This is a known bug and will be fixed in the next release. Here, behold Uno Platform Hello World app running on Surface Duo!
Using the Surface Duo SDK
The second part of the Surface Duo puzzle is the SDK, which lights up the unique capabilities of the dual-screen device. Xamarin.Android developers can find the Xamarin.DuoSdk right now here on NuGet.
The SDK gives you access to the Microsoft.Device.Display.DisplayMask
and Microsoft.Device.Display.HingeSensor
APIs and additional helper classes like ScreenHelper
. These help you quickly access the device capabilities of the Surface Duo. I will blog about these further, so stay tuned.
Hit the docs!
There is a lot of great content on Microsoft's Dual-Screen development website. I recommend reading through the Introduction to dual-screen devices article, which allows us to take a peek into the philosophy of how Microsoft approaches this unique new form factor. All of the guidelines apply to Surface Neo as well.