The Android and iOS backends give an app host what the desktop backends give it, through the same public types: PlatformApp, Window,
PlatformEvent, InputInjector. The app draws only when something changed; between events the loop sleeps (idle CPU is zero).
Hosting
Both hosts are NativeAOT programs. Reference the package and publish for linux-bionic-arm64 / linux-bionic-x64 (Android) or
ios-arm64 / iossimulator-arm64 (iOS); the package's targets file does the rest: it selects NativeAOT, generates the entry shim that
calls your Main (set OnePlatformMain if it is not global::Program.Main), and on Android points the compiler at the NDK
(ANDROID_NDK or AndroidNdkPath). Packaging into an APK or an app bundle is the packager's job; MobileHosting lists what it must
write.
The first restore needs a few lines in the app's project file
A package's build files reach a project only after the first restore has finished, so that restore cannot see what this package's targets
say about iOS and Android: dotnet publish -r ios-arm64 fails with NETSDK1203 (the SDK does not list iOS as a NativeAOT target) and
-r linux-bionic-arm64 with NETSDK1112 (the runtime pack was not downloaded). Nothing a package ships can change that, because the
package is not there yet. Put the lines for your platform in the app's .csproj; once restore has run, the package's own targets take over (a
target of the same name replaces yours, so nothing is downloaded twice).
iOS:
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('ios'))"><PublishAot>true</PublishAot></PropertyGroup> <Target Name="OnePlatformIosPacks" BeforeTargets="ProcessFrameworkReferences" Condition="$(RuntimeIdentifier.StartsWith('ios'))"> <ItemGroup> <KnownILCompilerPack Update="Microsoft.DotNet.ILCompiler" ILCompilerRuntimeIdentifiers="%(ILCompilerRuntimeIdentifiers);ios-arm64;iossimulator-arm64" /> </ItemGroup> </Target>
Android:
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))"><PublishAot>true</PublishAot></PropertyGroup> <Target Name="OnePlatformRestoreBionic" BeforeTargets="CollectPackageDownloads" Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))"> <ItemGroup> <PackageDownload Condition="'$(_IsPublishing)' != 'true'" Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler" Version="[$(BundledNETCoreAppPackageVersion)]" /> <PackageDownload Include="Microsoft.NETCore.App.Runtime.NativeAOT.$(RuntimeIdentifier)" Version="[$(BundledNETCoreAppPackageVersion)]" /> </ItemGroup> </Target>
A packaging tool that publishes for the app can instead pass the same two things on the command line (-p:PublishAot=true) and a targets file
through CustomAfterMicrosoftCommonTargets, which restore does evaluate.
Android
- The activity class is
dev.oneplatform.OnePlatformActivity(MobileHosting.AndroidActivityClass). It carries the input connection, the keyboard height, clipboard, open-URL and share hooks. A plainNativeActivitystill runs the app, but those calls then throwMobileCapabilityExceptionnaming the class. - It ships prebuilt:
build/android/OnePlatformActivity.dexin the package (MSBuild propertyOnePlatformActivityDex). Add the file to the APK asclasses.dex, or as the nextclassesN.dexbeside the app's own. The app developer needs no JDK. The Java source,build/android/OnePlatformActivity.java, ships beside it. The dex is built when OnePlatform is packed, bytools/build-activity-dex.sh(javac --release 8and the Android SDK'sd8); the same source and tool versions give the same bytes. - Manifest values:
MobileHosting.AndroidConfigChanges(android:configChanges, so rotation and size changes arrive as events instead of recreating the activity),AndroidWindowSoftInputMode(adjustNothing: the app lays itself out aroundWindow.KeyboardHeight),AndroidEnableOnBackInvokedCallback(false: Back arrives asBackRequested), theandroid.app.lib_namemeta-data naming your library, minimum APIMobileHosting.AndroidMinSdk(26). - With target SDK 35 the window is edge-to-edge:
Window.SafeAreais how the app keeps clear of the system bars.
iOS
MobileHosting.IosInfoPlistKeys()gives the Info.plist keys (scene manifest namingOnePlatformSceneDelegate, orientations, full screen, status-bar appearance). The executable'sMainis the generatedOnePlatformIosEntry, which runsIosAppHost.Run; yourMainruns on its own thread once the window exists.- The scale is
UIScreen.nativeScale, soWindow.Scaleis 2 or 3 on current devices.
Input
- Touch arrives as pointer events with
PointerTypeTouch, a stable per-fingerPointerIdandIsPrimary(the first finger down is primary, as in the Pointer Events specification); down, move, up and cancel. Pen and mouse (iPad pointer, Android mouse) arrive with their ownPointerKind, andPressurewhere the system reports it. - Soft keyboard:
Window.SetTextInput(true, options, x, y, width, height)shows it for the field at that rectangle andSetTextInput(false)hides it.TextInputOptionscarriesKeyboardType(text, email, number, url, password),ReturnKeyandAutocorrect(off by default: an app field wants what was typed). Composition arrives asTextComposition(preedit text and cursor) followed byTextInput(commit). Hardware keyboards arrive as ordinary key events. - Keyboard and insets:
KeyboardChangedcarries the height the keyboard covers from the bottom edge;Window.KeyboardHeight,ContentInsets(safe area plus keyboard) andVisibleAreagive the layout.SafeAreaChangedreports notches, bars and the home indicator. On iOS a floating or undocked keyboard covers nothing, soKeyboardHeightis 0 for it.WindowInsetsholds the arithmetic (Combine,Remaining,ScrollToReveal). Below Android 11 the keyboard height comes from the window's visible frame, an approximation that includes any system bar changes. - System bars: visible by default.
WindowOptions.SystemBarsandWindow.SetSystemBars(SystemBars.Hidden)hide the status and navigation bars (Android) or the status bar, home indicator and edge gestures (iOS). On AndroidSafeAreafollows; on an iPhone with a camera cut-out it keeps the cut-out's inset (top 62 pt on an iPhone 17) and the home indicator's, whether or not the bars are shown. - Status-bar style:
WindowOptions.SystemBarStyleandWindow.SetSystemBarStyle(SystemBarStyle.LightContent | DarkContent | Auto)pick the colour of the status bar's icons and text (and Android's navigation bar) to contrast with what the app draws behind them.Autoleaves the system's choice. Android uses the activity (WindowInsetsControllerappearance,systemUiVisibilitybefore API 30; an activity from before this call throwsMobileCapabilityExceptionfor a style other thanAuto); iOS setspreferredStatusBarStyle. Desktop windows ignore it without error.
Lifecycle
AppLifecycle (Paused, Resumed, LowMemory), SurfaceLost and SurfaceCreated (the app must stop drawing between them; Android also
destroys the surface when the app goes to the background), WindowResized, WindowScaleChanged, OrientationChanged (ScreenOrientation),
BackRequested (Android's Back button and gesture). Nothing is drawn while in the background.
Back follows Android's navigation guidance: BackRequested goes to the app first. When the app has nothing to go back to and closes its last window, the activity finishes and the task leaves the foreground (the launcher or the previous app shows). The process can stay cached for a while; a later launch starts the app anew.
The window extends into the display cut-out (layoutInDisplayCutoutMode always, or short edges before Android 11) and the bar colours are transparent, so the page is never covered by a black status-bar strip; Window.SafeArea includes the cut-out, so content keeps clear of it. The accessibility bridge reports node bounds from the window's corner, the origin of the surface the app draws on.
Presenting pixels
Window.PresentPixels draws a BGRA image on Android (ANativeWindow_lock) and iOS (a layer over the Metal layer), so a device without a
usable GPU path still shows the app. CanPresentPixels says whether it will work.
Open an address and share
PlatformApp.OpenUrl(url)opens anhttp,https,mailtoorteladdress in the system's handler: anACTION_VIEWintent on Android,UIApplication.openon iOS. It also works on desktops: the XDG OpenURI portal on Linux,ShellExecuteon Windows,NSWorkspaceon macOS (ShellUnavailableExceptionwhen the portal or a handler is missing).PlatformApp.Share(new ShareRequest(text, title))shows the share sheet (Android chooser, iOS activity sheet). Desktops have none and throwMobileCapabilityException.- A missing capability is always a typed exception naming what was expected, never a silent no-op.
Testing: input injection
InputInjector (PlatformApp.Injector) posts through the same path real input takes inside the app: TouchDown/Move/Up/Cancel, Tap,
Swipe, Pinch, Text, Composition, KeyboardChanged, OrientationChanged, SafeAreaChanged. With the headless backend these run
on any machine, so touch tracking, insets and composition logic are tested without a device. PlatformApp.NativeCommand carries a few
iOS-only test commands (describe, orientation, text_insert, text_mark, text_unmark, text_delete). orientation takes UIKit's names (landscape-left is UIKit's landscapeLeft, which Window.Orientation reports as ScreenOrientation.LandscapeRight, because ScreenOrientation names the side the top of the portrait screen turns towards, as on Android).
tests/OnePlatform.MobileProbe is a small app that logs every event as a probe: line (logcat on Android, stdout on iOS) and has buttons for
each keyboard type, the clipboard, open-URL, share, composition and system bars. android/ and ios/ hold the scripts that build it into an
APK or an app bundle and, on Android, drive it on an emulator.
Console output on iOS
The runtime's console on iOS goes to the system log. The host also writes standard output and error to file descriptor 1, so a launcher
that gives the app a stdout (simctl launch --console, or a debugger) sees it, and to Documents/oneplatform-stdout.txt. (On the current simulator, simctl launch --stdout=<file> creates no file for any app, so use --console or read the Documents copy.)