Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

Android-NativeAOT

> 编程语言
Open source

A .NET 8, NativeAOT example on Android

99 stars0 likes0 views
WebsiteGitHub

About

A .NET 8, NativeAOT example on Android

Android-NativeAOT

A .NET 8, NativeAOT example on Android.

Getting started

Configure your environment: the following environment variables are required:

  • ANDROID_NDK_HOME: The path to an Android NDK installation.
  • ANDROID_HOME: The path to an Android SDK installation.

Build the project:

bash
dotnet build
dotnet publish DotNet/libdotnet.csproj
(cd Native && ./gradlew assembleRelease)

Install the app:

bash
$ANDROID_HOME/platform-tools/adb install Native/app/build/outputs/apk/release/app-release.apk

Run the app:

bash
$ANDROID_HOME/platform-tools/adb shell am start com.jonathanpeppers.nativeaot/android.app.NativeActivity

Example using SkiaSharp

This sample has a C++ Android Studio project:

  • Uses Native Activity
  • No Java/Kotlin code
  • Configures OpenGL
  • Calls into C# / managed code
  • Managed code uses SkiaSharp for rendering a random Skia shader
  • Tap input randomly changes the shader

Some screenshots of the Skia content:

(Note these look completely smooth on a Pixel 5, I just tried to snap quick gifs with Vysor)

The C# side is a:

  • .NET 8 class library
  • Built with RID linux-bionic-arm64
  • Uses the SkiaSharp NuGet package, as one would.
    • Used a nightly build of SkiaSharp, as I wanted a feature from Skia 3.0

App Size

The release .apk file of the SkiaSharp sample is ~4.26 MB

A breakdown of the files inside:

…

libdotnet.so is ~1.07 MB, and libSkiaSharp.so is ~8.5MB!

If we reduce this to a "Hello World" example:

  • hello.apk is ~430 KB!
  • libdotnet.so (uncompressed) is ~821 KB!

Startup Time

The average of 10 runs on a Pixel 5 of the SkiaSharp sample:

log
Average(ms): 121
Std Err(ms): 3.29983164553722
Std Dev(ms): 10.434983894999

Average of 10 runs on a Pixel 5 of the "Hello World" example:

log
Average(ms): 120.9
Std Err(ms): 2.97937353594118
Std Dev(ms): 9.42160637400367

They might be effectively the same.

For comparison (as of .NET 8), a dotnet new android app is about ~180ms on a Pixel 5, and dotnet new maui is about ~560ms.

Source: https://github.com/jonathanpeppers/maui-profiling

"Hello World" Example

See the HelloWorld branch.

I had this managed code:

csharp
[UnmanagedCallersOnly(EntryPoint = "ManagedAdd")]
public static int ManagedAdd(int x, int y) => x + y;

I created a C++ Android project using NativeActivity, and I called the managed code from C++:

cpp
// in dotnet.h
extern "C" int ManagedAdd(int x, int y);

// in native-lib.cpp
int result = ManagedAdd(1, 2);
__android_log_print (ANDROID_LOG_INFO, TAG, "ManagedAdd(1, 2) returned: %i", result);

Results in the message:

log
01-31 11:42:44.545 28239 28259 I NATIVE  : Entering android_main
01-31 11:42:44.550 28239 28259 I NATIVE  : ManagedAdd(1, 2) returned: 3

See DotNet/README.md on how to build libdotnet.so.

Notes

Console.WriteLine() doesn't work because it basically just writes to Unix stdout. stdout does not appear in adb logcat output, as you have to call __android_log_print instead.

This was an interesting example, to start a thread that processes stdout and calls the appropriate Android API:

  • https://codelab.wordpress.com/2014/11/03/how-to-use-standard-output-streams-for-logging-in-android-apps/

Instead, we can p/invoke into:

csharp
[DllImport("log", EntryPoint = "__android_log_print", CallingConvention = CallingConvention.Cdecl)]
public static extern int LogPrint(LogPriority priority, string tag, string format);

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#androidcsharpdotnetnativeaot

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言