Repository navigation
fix(android): Keep Java resources in incremental APKs - #25123
Conversation
On net10.0-android, an incremental repackage makes BuildArchive drop every Java resource of AAR/JAR dependencies (dotnet/android#11543, fixed only in the .NET 11 workload). Losing META-INF/services breaks kotlinx.coroutines Dispatchers.Main, crashing apps that use androidx.window (e.g. via Uno.UI.Foldable) on every other build. Uno.Sdk now deletes the stale intermediate archive right before it gets repackaged, so up-to-date packages stay untouched. Opt out with UnoDisableIncrementalApkWorkaround=true. Fixes #24520 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DZqARsYT34zwsK3y97Vr4G
Drives Uno.Common.Android.targets against stubs of the .NET Android packaging targets: a stale package must start without the previous archive, while an up-to-date one, net11.0 and the opt-out keep it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DZqARsYT34zwsK3y97Vr4G
|
Claude finished @MartinZikmund's task in 22s —— View job Review of #25123: Keep Java resources in incremental APKsVerdict: ship. I found no blocking issues and posted no inline comments. I reviewed the diff by inspection only. I did not build or run the tests. What I checked
Non-blocking notes
|
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
|
Claude finished @MartinZikmund's task in 13s —— View job Re-review of #25123 after latest pushVerdict: ship. No new findings and no inline comments. I reviewed by inspection only. I did not build or run the tests.
No specific request came with the |
|
Thanks for the review. On the non-blocking notes:
Separately, the CodeQL |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25123/wasm-skia-net9/index.html |
GitHub Issue: closes #24520, closes #23938
PR Type:
🐞 Bugfix
What changed? 🚀
Problem
On .NET 10 Android, every other incremental build produces an APK with no Java resources from AAR/JAR dependencies: no
META-INF/services/*. The classes are still dexed, butServiceLoaderfinds nothing. Any app that calls kotlinx.coroutinesDispatchers.Mainthen dies at launch:In Uno Platform apps this is reached through the Foldable add-in →
androidx.windowWindowInfoTrackerCallbackAdapter. The in-repo SamplesApp Android head crashed this way on local Debug builds.Root cause
This is a .NET for Android SDK bug, dotnet/android#11543. Uno Platform doesn't cause it:
BuildArchiveadds all of its entries to anexistingEntrieslist.continues without removing the entry fromexistingEntries.dotnet new androidapp alternates between 2 and 0 services files the same way). Clean builds, which CI always does, are always good. That's why this only hurt local development.It's fixed upstream in dotnet/android#11552 (main) and #12463 (release/11.0.1xx-rc1), but not backported to 10.0 (current workload 36.1.69).
Fix
New
src/Uno.Sdk/targets/android-workarounds.targets, imported fromUno.Common.Android.targets, so every Uno.Sdk Android app gets it, SamplesApp included. It follows the existingxamarin-ios-workarounds.targetspattern:BeforeTargets="_BuildApkFastDev"/"_BuildApkEmbed"and delete the previous intermediate archive ($(ApkFileIntermediate)/$(_BaseZipIntermediate)).BuildArchivethen builds from scratch instead of taking the buggy refresh path.Inputs/Outputs($(_BuildApkFastDevStaticInputs),$(_BuildApkEmbedInputs)→$(_BuildApkEmbedOutputs)), so an up-to-date package is left alone. They only run when the SDK is about to repackage anyway.TargetFrameworkVersion < 11.0, because .NET 11 has the upstream fix.UnoDisableIncrementalApkWorkaround=true.The targets depend on private SDK names (
_BuildApkFastDevStaticInputs,_BuildApkEmbedInputs/Outputs,_BaseZipIntermediate,ApkFileIntermediate). This workaround should be removed once dotnet/android#11552 is backported to 10.0, or when 10.0 Android support is dropped. Apps that don't use Uno.Sdk aren't covered; they can copy the upstream workaround target.Validation
Runtime: SamplesApp Android head, Debug net10.0-android, Pixel 7 API 35 emulator, deployed with
-t:Install,Main.Android.csunmodified0e281d88ddf): a clean build has both services files; the incremental rebuild has 0, and the app crashes at launch with the stack above.META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactoryand…CoroutineExceptionHandler.sample=Buttons/Button_Eventslaunches and renders, with no MainDispatcher error in logcat.-p:UnoDisableIncrementalApkWorkaround=truereproduces the crash, which confirms the targets are what fixes it.Runtime: throwaway apps with the targets imported
base.zipalternates 61/0 → 78/2 entries without the workaround and stays at 78/2 with it.AndroidDispatcherFactoryis kept whenDispatchers.Mainis reachable, and the app logs "Main dispatcher: Dispatchers.Main".Not covered: in SamplesApp,
packaged_resourcesis always newer, so the up-to-date skip shows only in the throwaway app and the unit test. A full SamplesApp Release Android build was not run.Test:
Given_AndroidIncrementalApkWorkaroundinUno.UI.Tasks.Tests, 6 cases. It imports the realUno.Common.Android.targetsnext to stubs of the SDK targets with the same names, conditions andInputs/Outputs. It checks that the archive is deleted only when the package is stale, kept when it is up to date, skipped on net11.0, and skipped with the opt-out. Reverting the fix makes the two stale-package cases fail.The regression guard is an MSBuild-level test, not a runtime test. CI always does clean Android builds, which never hit the bug, so a runtime
Dispatchers.Maincheck or an APK-content check couldn't fail before the fix.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01DZqARsYT34zwsK3y97Vr4G