---
title: "Run and test a C# app on the Android emulator"
url: https://recursiveai.org/oneapp/cookbook/run-csharp-app-on-android-emulator/
description: "Build and launch a C# OneApp project on the Android emulator, then tap a button, type into a field, and swipe a list from the terminal."
version: "1.2.1"
---

```shell
dotnet add package RecursiveAI.OneApp
dotnet tool install -g RecursiveAI.OneApp.Cli
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

Use a Linux x86-64 host with the Android SDK (platform, build-tools, and platform-tools), the NDK, and a POSIX shell with `jq`. These steps don’t cover Windows or macOS hosts. [Start the emulator from the command line](#how-do-i-launch-the-android-emulator-from-the-command-line) and wait until Android finishes booting.

```shell
app=$(oneapp run . --android | jq -er .info)
oneapp tap '#count' --app "$app"
oneapp type Ada --into '#name' --app "$app"
oneapp swipe '#list' --dy -140 --app "$app"
```

Unzip [the example](https://recursiveai.org/oneapp/cookbook/run-csharp-app-on-android-emulator/run-csharp-app-on-android-emulator.zip), then run the commands above from the unzipped folder. The zip pins OneApp 1.2.1; install the matching CLI with `--version 1.2.1` if you want the same tool version.

`oneapp run` prints JSON with the path to a connection file in `info`; `jq` extracts that path for the `--app` arguments.

## Full program

```csharp
using OneApp;

public static class Program
{
    public static int Main(string[] args)
    {
        using var host = AppHost.Create(new AppOptions(new MainPage())
        {
            Title = "EmulatorTest",
            AppId = "org.example.emulatortest",
        });
        host.Run();
        return 0;
    }
}
```

OneApp builds the `MainPage` class from `MainPage.html` when you build the project. These are the controls the test targets:

```html
<main class="page">
  <button id="count" on:click="Count">Taps: {Taps}</button>
  <label for="name">Name</label>
  <input id="name" value="{Name}" on:input="Changed" />
  <p id="greeting">Hello, {Name}</p>
  <section id="list" class="list">
    <p>Start of list</p>
    <p id="last">End of list</p>
  </section>
</main>
```

The included `MainPage.cs` increments `Taps` and copies each input event’s value to `Name`. `MainPage.css` gives the list a 120-pixel scroll area and puts `#last` below its initial view. In the example folder, `sh test.sh` launches the app, runs the three actions, and reads the result back:

```text
Taps: 1
Hello, Ada
End of list
```

If `oneapp run` can’t find a device, run `adb devices` and wait until the emulator shows `device`, not `offline`.

## Variations

**Choose an emulator when more than one device is attached.** Use its serial from `adb devices`. Replace the example serial with yours:

```shell
oneapp run . --android --serial emulator-5554
```

## Related recipes

- [Check a C# Android app’s accessibility with UI Automator](https://recursiveai.org/oneapp/cookbook/test-android-app-accessibility-talkback-uiautomator/)
- [Automate UI tests for a C# desktop app](https://recursiveai.org/oneapp/cookbook/drive-desktop-app-from-tests/)

## The short answer

Start an Android virtual device and run `oneapp run . --android` from a OneApp project. OneApp builds a Debug package for that device, installs it, and launches the app. It forwards the app’s local test listener to your computer with `adb forward`. Use the returned `info` file with `--app` so `tap`, `type`, `swipe` and `query` all reach the app you just launched.

## How do I launch the Android emulator from the command line?

Create an Android Virtual Device first. A virtual device is a named configuration that includes an Android system image. The [Android emulator command-line guide](https://developer.android.com/studio/run/emulator-commandline#startup-options) covers the startup options. With the SDK’s `emulator` and `platform-tools` directories on your path, list your devices, then boot one by name. The command below uses `Pixel_API_35` as an example name; substitute yours.

```shell
emulator -list-avds
emulator -avd Pixel_API_35 -no-window
```

Leave the emulator running and issue `adb devices` from another terminal. Wait until Android has finished booting and the home screen is available before running the app. The emulator’s name in `-avd` is not the serial you pass to OneApp: that serial comes from `adb devices`.

## Can I run an APK on an emulator?

Yes. If you already have an APK, Android’s [`adb install`](https://developer.android.com/tools/adb#move) can install it on the emulator. If you have the C# source and want to drive the UI from the terminal, use `oneapp run . --android` instead. It starts a Debug build with the listener and returns the file the other OneApp commands use. Installing an APK alone does not set up that connection.

## How do I test Android touch input from the command line?

Use `tap` on a button’s CSS selector to send touch events instead of invoking its handler directly. `type --into` targets an editable field; add `--clear` when replacing an existing value. Start a swipe inside the scrollable element. A negative `--dy` moves the finger up to scroll toward later items. Swipe distances are in CSS pixels, not emulator screen pixels. Check an observable result after each action: a changed counter, new text, or a list item that is now visible and can be hit. The [harness reference](https://recursiveai.org/oneapp/docs/harness/) lists the query fields and what they mean.
