Recursive AI

Phones and tablets (Android and iOS)

All oneplatform docs

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:

XML
<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:

XML
<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 plain NativeActivity still runs the app, but those calls then throw MobileCapabilityException naming the class.
  • It ships prebuilt: build/android/OnePlatformActivity.dex in the package (MSBuild property OnePlatformActivityDex). Add the file to the APK as classes.dex, or as the next classesN.dex beside 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, by tools/build-activity-dex.sh (javac --release 8 and the Android SDK's d8); 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 around Window.KeyboardHeight), AndroidEnableOnBackInvokedCallback (false: Back arrives as BackRequested), the android.app.lib_name meta-data naming your library, minimum API MobileHosting.AndroidMinSdk (26).
  • With target SDK 35 the window is edge-to-edge: Window.SafeArea is how the app keeps clear of the system bars.

iOS

  • MobileHosting.IosInfoPlistKeys() gives the Info.plist keys (scene manifest naming OnePlatformSceneDelegate, orientations, full screen, status-bar appearance). The executable's Main is the generated OnePlatformIosEntry, which runs IosAppHost.Run; your Main runs on its own thread once the window exists.
  • The scale is UIScreen.nativeScale, so Window.Scale is 2 or 3 on current devices.

Input

  • Touch arrives as pointer events with PointerType Touch, a stable per-finger PointerId and IsPrimary (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 own PointerKind, and Pressure where the system reports it.
  • Soft keyboard: Window.SetTextInput(true, options, x, y, width, height) shows it for the field at that rectangle and SetTextInput(false) hides it. TextInputOptions carries KeyboardType (text, email, number, url, password), ReturnKey and Autocorrect (off by default: an app field wants what was typed). Composition arrives as TextComposition (preedit text and cursor) followed by TextInput (commit). Hardware keyboards arrive as ordinary key events.
  • Keyboard and insets: KeyboardChanged carries the height the keyboard covers from the bottom edge; Window.KeyboardHeight, ContentInsets (safe area plus keyboard) and VisibleArea give the layout. SafeAreaChanged reports notches, bars and the home indicator. On iOS a floating or undocked keyboard covers nothing, so KeyboardHeight is 0 for it. WindowInsets holds 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.SystemBars and Window.SetSystemBars(SystemBars.Hidden) hide the status and navigation bars (Android) or the status bar, home indicator and edge gestures (iOS). On Android SafeArea follows; 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.SystemBarStyle and Window.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. Auto leaves the system's choice. Android uses the activity (WindowInsetsController appearance, systemUiVisibility before API 30; an activity from before this call throws MobileCapabilityException for a style other than Auto); iOS sets preferredStatusBarStyle. 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 an http, https, mailto or tel address in the system's handler: an ACTION_VIEW intent on Android, UIApplication.open on iOS. It also works on desktops: the XDG OpenURI portal on Linux, ShellExecute on Windows, NSWorkspace on macOS (ShellUnavailableException when 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 throw MobileCapabilityException.
  • 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.)