Skip to content

Incremental Android build drops the kotlinx-coroutines-android AAR, producing an APK that crashes on launch #23938

Closed

Description

@MartinZikmund

Current behavior

Incrementally rebuilding an Android head after the sources change produces an APK that is missing the kotlinx-coroutines-android AAR. The app then dies on launch, because androidx.window needs it to obtain the Main dispatcher:

E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: java.lang.ExceptionInInitializerError
E AndroidRuntime:   at kotlinx.coroutines.Dispatchers.getMain(Dispatchers.kt:20)
E AndroidRuntime:   at androidx.window.layout.WindowInfoTrackerImpl.windowLayoutInfo(WindowInfoTrackerImpl.kt:66)
E AndroidRuntime:   at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter.addWindowLayoutInfoListener(...)
E AndroidRuntime:   at crc64....ApplicationActivity.n_onStart(Native Method)
E AndroidRuntime: Caused by: java.lang.IllegalStateException: Module with the Main dispatcher is missing.
E AndroidRuntime:   Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'
E AndroidRuntime:   and ensure it has the same version as 'kotlinx-coroutines-core'

The build itself reports success — the failure only shows up at runtime, and only on onStart.

Expected behavior

An incremental rebuild produces a working APK, or fails the build.

How to reproduce it

  1. Build SamplesApp.Skia.netcoremobile for net10.0-android in Release. Deploy — it works.
  2. Change a source file in Uno.UI (or check out a different commit).
  3. Rebuild the same project without clearing obj/bin. The build succeeds.
  4. Deploy and launch — it crashes as above.
  5. rm -rf src/SamplesApp/SamplesApp.Skia.netcoremobile/obj/Release bin/Release and rebuild. The APK works again.

Reproduced five times in a row today on net10.0-android, Release, SDK 10.0.300. A clean package has fixed it every time.

Notes

The failing call is ApplicationActivity.OnStart → WindowInfoTrackerCallbackAdapter.addWindowLayoutInfoListener, i.e. the foldable posture support, so it reproduces on every launch rather than only on a fold.

The symptom looks like application code failing, which makes it easy to misattribute — it cost several debugging cycles before the pattern (always fixed by a clean build, always returns on the next incremental one) made the cause obvious. Failing the build, or ensuring the AAR is re-merged on incremental builds, would both be preferable to a successful build that produces a broken APK.

Activity

  1. added
    kind/bug
    on Jul 31, 2026
  2. self-assigned this
    on Aug 3, 2026
  3. ajpinedam commented on Aug 3, 2026

    @ajpinedam
    Contributor

    Reproduced and traced: this is an upstream .NET for Android packaging bug, tracked at dotnet/android#11543. On an incremental repackage, the BuildArchive task silently drops all AAR java resources from the APK — including META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory, which is why Dispatchers.Main can't be resolved and the app crashes at startup while the build still reports success. It affects both Release dotnet publish and Debug -t:Install, on Windows and macOS.

    Until the fix lands upstream, a cheaper workaround than a full clean is deleting the intermediate APK before packaging, in the Android head project:

    <Target Name="_CleanIntermediateApk" BeforeTargets="_BuildApkEmbed;_BuildApkFastDev">
      <Delete Files="$(ApkFileIntermediate)" Condition="Exists('$(ApkFileIntermediate)')" />
    </Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions