---
title: "Mobile"
url: https://recursiveai.org/oneapp/docs/mobile/
description: "How a OneApp page behaves on a phone or tablet: touch, Back, the soft keyboard, and building, signing and driving apps on Android and on iOS and iPadOS."
version: "1.1.1"
source: https://github.com/recursive-ai-oss/oneapp-csharp/blob/e570921db23c7c5822ec666013f713028d088d8c/docs/mobile.md
---

# Mobile

How a OneApp page behaves on a phone or tablet. Both mobile hosts share this part; platform sections follow.

## Touch

A finger drives the page the way a touch browser does. `OneApp.AppHost` turns the platform's touch events into DOM pointer events with `pointerType: "touch"`; the first finger acts, a second one cancels what the first began.

| Finger | Page sees |
|---|---|
| Press and release within 8 CSS px | `pointermove`, `pointerdown`, `pointerup`, then `click`; `:hover` and `:active` apply while it is down and end when it lifts |
| Move past 8 CSS px | `pointercancel`, then the box under the finger scrolls with it (scroll chains to the parent at the end, as wheel scrolling does) |
| Lift while moving | a fling: the speed of the last 100 ms (50 to 8000 CSS px/s) decays with a 325 ms time constant and stops at the end of the box |
| Touch during a fling | stops it, nothing else |

A fling draws frames only while it runs; an idle page stays at zero wakeups. The logic is `OneApp.Mobile.TouchGestures` and is tested without a window.

## Back

The system's back gesture or button reaches `AppWindow.BackHandler` first. If that is unset or returns false, an open dialog, menu or list box (`[aria-modal="true"]`, `[role=menu]`, `[role=listbox]`) gets Escape, which closes it for a keyboard user too. With none open, the window closes, and closing the last main window ends the app.

## Soft keyboard

When a text field takes focus the host asks the platform to show the keyboard; the page lays out in the part of the window above it and the focused field is scrolled into view. The keyboard's layout and action key follow the field's `inputmode`, `type` and `enterkeyhint`.

## Android

The status bar's icon colour follows the page: `AppOptions.SystemBarStyle` is `Auto` by default (dark icons over a light colour at the top edge, light over a dark one, chosen again after each change to the page) and takes `LightContent` or `DarkContent` to fix it.

Touch hosts draw no scrollbars by default (`AppOptions.TouchScrollbars` and `AppWindowOptions.TouchScrollbars`, `Hidden` unless set to `Classic`); content scrolls by finger. A tap that hides the on-screen keyboard still lands on the element under the finger: the page keeps the keyboard-reduced layout until the finger lifts.

A OneApp app on Android is a NativeAOT shared library that the platform package's activity class (a `NativeActivity` subclass, `dev.oneplatform.OnePlatformActivity`) loads. The class carries the soft keyboard, clipboard, share and open-address hooks; the app's own code is all C#. The window is the activity's surface, drawn with Vulkan (or the CPU path when no GPU driver answers) only when something changes; an idle app wakes no threads.

### The app

The activity calls `Program.Main(string[] args)` on the app's own thread. The class must be static-reachable as `Program.Main`, or named with `<OneAppAndroidMain>Namespace.Program.Main</OneAppAndroidMain>`. `Main` creates the `AppHost` and calls `Run` as on a desktop; `AppOptions.Backend` stays `Auto`.

```
dotnet new oneapp -n Notes
cd Notes
dotnet oneapp package . --format apk --debug-key        # Notes-1.0.0-android.apk, both ABIs
dotnet oneapp package . --format aab --keystore release.p12   # the bundle a store takes
dotnet oneapp install . --android                       # build for the connected device and install it
dotnet oneapp run . --android                           # the same, then start it with the harness reachable from this computer
```

### Tools

`oneapp` finds the Android SDK from `--sdk`, `ANDROID_HOME`, `ANDROID_SDK_ROOT` or `~/Android/Sdk` and says what to install when a piece is missing: `build-tools` (aapt2, zipalign), a `platforms` folder (android.jar), `platform-tools` (adb) and an `ndk` (the linker for the NativeAOT library, Linux x86-64 host). Signing and the key store are managed code. The activity class comes with `RecursiveAI.OnePlatform`: prebuilt as `classes.dex` when the package has it, otherwise as Java source that needs a JDK (17 or newer, `JAVA_HOME` or on `PATH`) with the SDK's `d8`; the error says so when there is none.

### Project properties

| Property | Meaning |
|---|---|
| `OneAppId` | The package name (`org.example.notes`; no `-`). |
| `OneAppName`, `OneAppVersion`, `OneAppIcon` | Launcher label, version name, icon. A square PNG becomes the adaptive icon's foreground (inset to the part every launcher shows); `OneAppAndroidIconBackground` (`#RRGGBB`, default white) is its background. |
| `OneAppAndroidVersionCode` | Overrides the version code (default `major*10000 + minor*100 + patch`). |
| `OneAppAndroidTargetSdk` | Default 34. From 35 the system draws windows edge to edge and the page needs `env(safe-area-inset-*)`, which the renderer does not have yet. Google Play asks for 35 or more. |
| `OneAppAndroidPermissions` | `;`-separated permissions the app asks for. Nothing else is requested; Debug builds add `INTERNET` for the harness. |
| `OneAppAndroidOrientation` | An `android:screenOrientation` value (default `unspecified`). |
| `OneAppAndroidMain` | The entry method (default `Program.Main`). |

### Signing

A Debug build or `--debug-key` is signed with a per-user key made on first use next to `signing.json` (`android-debug.p12`); devices and emulators accept it, stores do not. A release is signed with your own PKCS#12 key store: `--keystore FILE`, `ONEAPP_ANDROID_KEYSTORE`, `<OneAppAndroidKeystore>` or `"androidKeystore"` in `signing.json`, with the password in `ONEAPP_ANDROID_KEYSTORE_PASSWORD` or `"androidPassword"` (never a flag). APK Signature Scheme v2 is written in managed code. Convert a Java keystore with `keytool -importkeystore ... -deststoretype pkcs12`.

### Harness

`oneapp run --android` starts the Debug app with a listener on a device-local loopback port and a token, forwards it with `adb forward`, and writes the discovery file the other commands read, so `oneapp query`, `click`, `tap`, `swipe`, `type`, `press`, `wait`, `capture` (the picture comes back and is written on this computer) and `oneapp mcp` work as against a desktop app. Add `--serial S` when several devices are connected.

### Back and keyboard

The back gesture closes an open dialog, menu or list box and otherwise leaves the app (above). The soft keyboard shows when a text field takes focus, with the layout and action key the field's `inputmode`, `type` and `enterkeyhint` ask for (`email`, `tel`, `url`, `numeric`/`decimal`, `password`; `done`, `go`, `next`, `search`, `send`). The window is not resized (`adjustNothing`); the page lays out above the keyboard and the field stays in view. The system bars are shown, and the page gets the part they cover as the custom properties `--safe-area-inset-top`, `-right`, `-bottom` and `-left` (CSS pixels, on the root element), for `padding: calc(16px + var(--safe-area-inset-top, 0px))` and the like. Shell services a phone does not have (tray, global hotkeys, file portals, screenshots, notifications) fail with `ShellUnavailableException`; `AppShell.OnPhone` says so up front.

## iOS and iPadOS

An app built for `ios-arm64` (devices) or `iossimulator-arm64` (the Simulator) is a NativeAOT executable inside an app bundle. UIKit owns the main thread; the app's own `Main` runs on a thread of its own once the window exists, so the program needs a class `Program` with `static int Main(string[] args)` (top-level statements cannot be called). Nothing but our code, the one* libraries, the runtime and Apple's frameworks ships. Building needs a Mac with Xcode; no .NET workload is installed (OnePlatform's build file adds the two identifiers to the compiler pack's list and writes the program entry; the compiler and runtime packs are ordinary packages).

`samples/Phone` is a small app laid out this way; `samples/Relay` runs on iOS too (`IosBundleId` and `OnePlatformMain` in its project).

### Commands

```
oneapp run <project> --ios [--simulator NAME|UDID | --device ID] [--no-harness] [-- app args]
oneapp install <project> --ios [--simulator NAME|UDID | --device ID] [--no-harness]
oneapp package <project> --format simulator-app|ipa [--device ID] [--harness] [--distribution] [--output DIR]
```

`run` builds, installs, starts the app and prints where its listener is; `--app <info file>` then drives it like any other OneApp app. The bundle takes its id from `OneAppId` (or `IosBundleId`), its name from `OneAppName`, its version from `OneAppVersion`, its icon from `OneAppIcon` (a PNG, scaled to the sizes iOS looks for) and its orientations from `IosOrientation` (`all`, `landscape`, `portrait`).

### Signing

The Simulator takes an ad-hoc signature. A device needs a provisioning profile for the bundle id that lists the device, and a code-signing identity whose certificate the profile lists. Nothing is created for you:

- the profile is `--ios-profile FILE` (or `ONEAPP_IOS_PROFILE`, or `iosProfile` in `signing.json`), else the newest unexpired matching profile in `~/Library/MobileDevice/Provisioning Profiles` and Xcode's own folder (and `ONEAPP_IOS_PROFILES`);
- the identity is `--ios-identity NAME|SHA1` (or `ONEAPP_IOS_IDENTITY`, `iosIdentity`), else the first identity in the keychains the profile lists. Signing needs that keychain unlocked and the key's access list to allow `codesign`; a locked keychain makes `codesign` wait for a password nobody can type, so name an identity from an unlocked one.
- A development profile is used unless `--distribution` asks for an ad hoc or store one.

A wildcard bundle id in the profile (`com.example.*`) covers every app under that prefix.

### Development listener

A debug (or `--harness`) build listens on `127.0.0.1` with a token and writes `{"pid", "address", "token"}` to `Documents/oneapp-harness.json` inside the app's data folder. On the Simulator the folder is on the computer's disk and the port is the computer's own. On a device the port is on the device's loopback and Apple's tools offer no forwarding to it, so the `oneapp` tool reaches it over USB (or a network pairing the multiplexer lists) through the USB multiplexer, `/var/run/usbmuxd`, so the address in the info file is `usbmux:UDID:PORT`; the listener stays on loopback.

### Real touch for tests

`tools/ios-drive` is an XCUITest runner that sends taps, drags, typing, rotation and Home/activate to a running app on the Simulator or a device (see its readme).
