Skip to content

APK Tests on the Hyper V Emulator

David Ortinau edited this page Sep 3, 2024 · 2 revisions

.NET for Android APK Tests inside Hyper-V

On Windows, on my local machine I can run the following command to see the APK tests pass:

msbuild tests\RunApkTests.targets

NOTE: the APK tests projects were already built with xabuild.exe or setup-windows.exe installed

This will run the appropriate avdmanager commands to create a HAXM emulator suitable for running the APK-based tests

The dilemma is that our VSTS build agents are running inside Hyper-V. The HAXM emulator does not work inside a Hyper-V virtual machine. There is an update to Windows that will allow a Hyper-V VM and a HAXM emulator to run side-by-side on the host machine, but not inside a Hyper-V VM.

Visual Studio Emulator for Android

The Visual Studio Emulator is a Hyper-V based emulator, that we could theoretically use as an alternative.

This brings up a new set of issues:

  • This emulator seems like it may be discontinued. The newest image is API 23.
  • Nested virtualization in Hyper-V is a setting on the host machine. We would need to get this enabled for our VSTS build agents.

We would need to implement the equivalent of the avdmanager commands for this new emulator, and it seems like that could be wasted effort if the emulator is discontinued.

Additionally some of the APK tests crash when running on the Hyper-V emulator:

> ~\android-toolchain\sdk\platform-tools\adb.exe shell am instrument  -w "Xamarin.Android.JcwGen_Tests/xamarin.android.jcwgentests.TestInstrumentation"
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
INSTRUMENTATION_RESULT: shortMsg=Process crashed.
INSTRUMENTATION_CODE: 0

TBD if the test app crashing is a real issue or not.

Conclusion

Right now the only options for running APK tests on Windows would be:

  • Use a physical Windows machine for build agents, so HAXM works
  • Use a Windows machine (that could be a VM) that has a physical Android device connected
  • Use an ARM emulator, which may be too slow to be useful
Clone this wiki locally