Repository navigation
Description
Current behavior 🐛
The in-repo SamplesApp Android head (Debug, net10.0-android) crashes at startup on a clean emulator:
java.lang.ExceptionInInitializerError
at kotlinx.coroutines.Dispatchers.getMain(Dispatchers.kt:19)
at androidx.window.layout.WindowInfoTrackerImpl.windowLayoutInfo(WindowInfoTrackerImpl.kt:66)
at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter.addWindowLayoutInfoListener(WindowInfoTrackerCallbackAdapter.kt:53)
at crc64d0916be76e7aa092.ApplicationActivity.n_onStart(Native Method)
Caused by: java.lang.IllegalStateException: Module with the Main dispatcher is missing.
Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'
at kotlinx.coroutines.internal.MainDispatcherLoader.loadMainDispatcher(MainDispatchers.kt:35)
The dependency is not missing — the packaged APK simply contains no META-INF/services entries, so the ServiceLoader lookup that resolves Dispatchers.Main finds no factory. androidx.window (reached through the Foldable add-in in ApplicationActivity.OnStart) is the first caller to touch it, so the app dies before any content renders.
Analysis:
- The upstream artifact does ship the registration:
Xamarin.KotlinX.Coroutines.Android1.11.0.1 →lib/net10.0-android36.0/Xamarin.KotlinX.Coroutines.Android.aar→libs/*.jarcontainsMETA-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory(52 bytes) andMETA-INF/services/kotlinx.coroutines.CoroutineExceptionHandler. - The classes are dexed correctly:
AndroidDispatcherFactoryandHandlerDispatcherare present inclasses2.dexof the built APK. - The built APK contains exactly three
META-INFentries —MANIFEST.MF,ANDROIDD.SF,ANDROIDD.RSA— and nothing else. - Nothing appears to ask for that exclusion: the .NET Android SDK's defaults (
Sdk/AutoImport.props) only addDebugProbesKt.binand*.kotlin*to@(AndroidPackagingOptionsExclude), and this repo sets noAndroidPackagingOptions*items at all. - The Debug head pins
AndroidLinkTool=r8with aproguard.cfgof-dontshrink -dontoptimize -dontobfuscate, whose comment already anticipated "the kotlinx.coroutines Main dispatcher behind androidx.window" being stripped. Classes do survive now, but the service registration does not, so this looks like jar resource collection rather than shrinking.
Expected behavior 🎯
META-INF/services/* entries from dependency jars are packaged into the APK, so ServiceLoader-based registration works and Dispatchers.Main resolves.
How to reproduce it (as minimally and precisely as possible) 🔬
This reproduces with the repository's own samples head rather than a template app:
cd src
dotnet build SamplesApp/SamplesApp/SamplesApp.csproj -f net10.0-android \
-p:UnoTargetFrameworkOverride=net10.0-android -t:Install -p:AdbTarget="-s emulator-5554"
adb shell am start -n uno.platform.samplesapp.skia/crc6448f3b0362cbf4bc9.MainActivity
The app shows "keeps stopping"; adb logcat carries the stack above. Inspecting the APK shows the cause:
unzip -l src/SamplesApp/SamplesApp/bin/Debug/net10.0-android/uno.platform.samplesapp.skia-Signed.apk | grep META-INF
Observed on an API 34 x86_64 emulator, .NET Android SDK 36.1.69, Vulkan on SwiftShader.
Workaround 🛠️
Package the two service files as a small jar and reference it from the Android head:
<ItemGroup Condition="'$(_Platform)' == 'android'">
<AndroidJavaLibrary Include="coroutines-services.jar" />
</ItemGroup>where the jar holds only META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory and META-INF/services/kotlinx.coroutines.CoroutineExceptionHandler, copied verbatim from the upstream artifact. With that in place the entries appear in the APK and the app starts normally.
Renderer 🎨
- Skia
- Native
Affected platforms 📱💻🖥️
Android
Uno.Sdk version (and other relevant versions) 📦
Built from the repository (master at the time of writing), net10.0-android, .NET Android SDK 36.1.69, Xamarin.KotlinX.Coroutines.Android 1.11.0.1, Xamarin.AndroidX.Window.WindowJava 1.3.0.7.
IDE version 🧑💻
dotnet CLI build (no IDE).
Anything else we need to know? 💬
Found while validating an unrelated Skia-Android change on a local emulator: the crash blocks any on-device run of the samples app from a Debug build, so it also blocks manual validation of Android work generally.
Activity
MartinZikmund commentedon Oct 1, 2026
This looks like the same problem as #23938, which was traced to an upstream .NET for Android packaging bug: dotnet/android#11543.
On an incremental repackage,
BuildArchivecan silently drop every AAR/JAR resource from the intermediate APK. That includesMETA-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory, while the classes themselves are still dexed. It matches the symptoms here: classes present inclasses2.dex, and only the signature entries underMETA-INFin the APK. The result alternates between good and bad on consecutive builds.If that is what happened here, a clean build (or deleting the intermediate APK before packaging) should produce an APK with the
META-INF/servicesentries. The workaround from #23938 is:dotnet/android#11543 was closed as completed on 2026-08-18. The fix may need a newer Android workload than 36.1.69, so it's worth retrying with an updated one.
fix(android): Keep Java resources in incremental APKs