Skip to content

Ultraviolet on Android

Cole Campbell edited this page Mar 3, 2018 · 3 revisions

Version 1.1 of the Ultraviolet Framework brought with it support for the Android operating system. This article details the steps needed to get an Ultraviolet project working on this platform.

The Basics

Due to the requirements of the SDL2 library, Ultraviolet-based applications require Android 3.1 (SDK Version 12). Furthermore, because Ultraviolet is a .NET project, you will need to install the Xamarin framework in order to build and deploy Ultraviolet-based applications which target Android.

Ultraviolet provides Android-targeted copies of all of its core libraries as part of their standard NuGet packages. In addition to the core libraries, the Ultraviolet.Shims.Android.dll compatibility shim must also be included as a reference in any project which targets Android. This assembly is responsible for providing Ultraviolet with services that provide platform-specific functionality.

Your code should be mostly compatible between platforms, with the exception of the Ultraviolet host. If you are using the built-in UltravioletApplication host, you will need to replace it with UltravioletActivity. If you're sharing code between platforms, you can do this with a simple #ifdef:

#if ANDROID
    [Android.App.Activity(Label = "GameActivity", MainLauncher = true, ConfigurationChanges = 
        Android.Content.PM.ConfigChanges.Orientation | 
        Android.Content.PM.ConfigChanges.ScreenSize | 
        Android.Content.PM.ConfigChanges.KeyboardHidden)]
    public class Game : UltravioletActivity
#else
    public class Game : UltravioletApplication
#endif

Content

Content assets should be added to the Android project as Android assets, which can be done by opening each asset file's properties panel in Visual Studio and setting the Build Action to AndroidAsset. You must also tell the Ultraviolet context to pull files from the Android asset list by calling UsePlatformSpecificFileSource() at some point during context initialization.

The UsePlatformSpecificFileSource() method is safe to call on all platforms; if called on a platform with no platform-specific file sources (such as the desktop platforms), it will do nothing.

Clone this wiki locally