Recursive AI

Build and sign an Android APK from a C# app

OneApp is a free, open-source framework for apps in .NET whose UI is HTML and CSS, drawn natively with no web view on Windows, macOS, Linux, iOS and Android, and run in the browser, from Recursive AI. MIT or Apache-2.0.

Build an installable APK on Linux x64 with the Android SDK and NDK.

Terminal
dotnet tool install -g RecursiveAI.OneApp.Cli

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

  1. Install Android SDK Build Tools, Platform Tools, the API 36 SDK Platform, and the NDK. API 36 provides the build tools with android.jar; the project still declares target API 35.
  2. Set ANDROID_HOME to the SDK directory. No .NET Android workload is needed.
  3. Unzip the example and open a terminal in that folder. For release signing, install a JDK with keytool. If you don’t already have a release keystore, create one and enter its password when prompted:
Terminal
keytool -genkeypair -alias app -keyalg RSA \
  -keysize 2048 -validity 10000 \
  -storetype PKCS12 -keystore release.p12

Set ONEAPP_ANDROID_KEYSTORE_PASSWORD in the packaging shell to that password before running the release command. Keep the keystore and password out of source control.

Terminal
oneapp package . --format apk --debug-key
oneapp package . --format apk \
  --keystore release.p12 --output release

The example is the full program below: unzip it and dotnet run.

Use the first command for testing and the second for release. Both write PocketNotes-1.0.0-android.apk; the second puts it in release/ so it doesn’t replace the test APK. dotnet run opens the desktop preview instead. Close it before packaging.

Full program

The zip includes PocketNotes.csproj, with the app host package already referenced (dotnet add package RecursiveAI.OneApp in an existing project):

XML
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <PublishAot>true</PublishAot>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <OneAppId>org.example.pocketnotes</OneAppId>
    <OneAppName>PocketNotes</OneAppName>
    <OneAppVersion>1.0.0</OneAppVersion>
    <OneAppAndroidTargetSdk>35</OneAppAndroidTargetSdk>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="RecursiveAI.OneApp" Version="1.2.1" />
  </ItemGroup>
</Project>

Program.cs uses a named Program.Main method so Android’s activity can call it. The HTML is inline; there are no assets to fetch.

C#
using OneApp;
 
public static class Program
{
    public static int Main(string[] args)
    {
        const string page = """
            <main style="padding:calc(16px + var(--safe-area-inset-top, 0px))
                                calc(16px + var(--safe-area-inset-right, 0px))
                                calc(16px + var(--safe-area-inset-bottom, 0px))
                                calc(16px + var(--safe-area-inset-left, 0px))">
              <h1>PocketNotes</h1>
            </main>
            """;
        using var host = AppHost.Create(new AppOptions(page)
        {
            Title = "PocketNotes",
            AppId = "org.example.pocketnotes",
        });
        host.Run();
        return 0;
    }
}

The CLI printed these JSON fields for the test build:

JSON
{
  "package": "org.example.pocketnotes",
  "versionCode": "10000",
  "abis": "arm64-v8a,x86_64",
  "debuggable": "false",
  "signing": "debug key"
}

The release command printed the same fields with "signing": "release key".

If --keystore points to a file that doesn’t exist, OneApp returns keystore_missing instead of falling back to a debug key.

Variations

Install the release APK on a connected device or running emulator with Android Debug Bridge (adb):

Terminal
adb install release/PocketNotes-1.0.0-android.apk

The short answer

Run oneapp package . --format apk --debug-key to build a signed APK for testing. For a release you distribute yourself, use --keystore release.p12 instead and supply its password through ONEAPP_ANDROID_KEYSTORE_PASSWORD. OneApp compiles the C# app ahead of time into a native library for each supported architecture, puts both libraries in the APK, then signs the package. It doesn’t install the APK or upload it to a store.

What is a signed APK file?

An APK contains the code and resources Android installs. Its signature tells Android which certificate signed it and lets the system detect changes after signing. OneApp writes an APK Signature Scheme v2 signature, which covers the package as a whole. The tool creates its own per-user debug keystore on first use, so you don’t need to make a key or register an account just to try the app.

A debug signature and a Debug build are separate choices. --debug-key chooses the signing certificate, not the build configuration. The command at the top still builds a Release app, with debuggable set to false. Use a debug key for local tests, not for your public releases. See Android’s app signing guide for the difference between debug and release certificates.

Why won’t Android install my new APK over the old one?

For a normal update, keep the same package ID (OneAppId) and signing certificate and raise the version code. OneApp derives that integer from OneAppVersion: 1.0.0 becomes 10000 and 1.0.1 becomes 10001. If your previous release already uses a different version-code sequence, set OneAppAndroidVersionCode explicitly rather than starting over.

Switching from the debug key to your release key changes the certificate, even if nothing else in the project changed. If you’re replacing a debug copy on a test device, uninstall that copy first; this removes its local app data. For apps you’ve already distributed, reuse your original signing key. Android compares the certificates when it installs an update.

All oneapp recipes