Skip to content

[xabt] Recover missing AAPT2 keep rules from incremental caches - #12969

Merged
simonrozsival merged 3 commits into
mainfrom
simonrozsival-aapt2-keep-rule-recovery
Oct 3, 2026
Merged

simonrozsival merged 3 commits into
mainfrom
simonrozsival-aapt2-keep-rule-recovery

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Part of #12940.

Summary

Repair already-damaged incremental obj trees where aapt_rules.txt is missing but packaged resources are still up to date. _CreateBaseApkInputs invalidates only _PackagedResources when a non-design-time Android application expects AAPT2-generated ProGuard rules and those rules are absent. The existing preparation and AAPT2-link targets then regenerate them.

This is distinct from #12950, which preserves and re-registers surviving rules during incremental builds. Its late _Aapt2ProguardRules calculation and skipped-target ProguardConfiguration/FileWrites registration remain intact. No extra collection target, new property, or broad obj cleanup is introduced.

Regression coverage

The new Release/CoreCLR/R8/trimmable fixture embeds an unbound Java JAR, so generated keeps for managed peers or app-authored Java cannot accidentally root the tested classes.

  • Delete only the merged rules, both with no source changes and with a Java-only change. Check regeneration, inclusion in R8's configuration, and retention of a manifest-only Activity plus a layout-only View and its inflation constructor in the final DEX.
  • After repair, require resource preparation/linking, Java compilation, and dex compilation to be skipped, with unchanged rules and packaged-resource timestamps.
  • Exercise _CreateBaseApkInputs with shrinking disabled, AndroidApplication=false, and DesignTimeBuild=true; packaged resources must remain untouched and rules must not be generated.

On unchanged main 976e552, both damaged-cache cases fail because the rules remain missing. The Java-only case runs R8 without AAPT2 rules and strips both JAR classes while _CreateBaseApk remains skipped. The existing #12950 regression passes on main.

Local validation

./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll \
  --filter 'FullyQualifiedName~IncrementalBuildTest.AaptRulesRemainInR8ConfigurationAfterIncrementalBuild|FullyQualifiedName~IncrementalBuildTest.AaptRulesAreRegeneratedAfterDeletion'

3 passed, 0 failed, 0 skipped in one focused invocation with the recovery enabled. Shipped task/target outputs and host test/configuration assemblies were rebuilt from this main-based branch using a private SDK/toolchain. No device was used.

Scope is limited to Xamarin.Android.Common.targets and IncrementalBuildTest.cs; no LLVM, native, binutils, bootstrap, or remapping changes or dependencies on other open PRs.

Invalidate packaged resources only when a non-design-time application requires generated ProGuard rules and its merged AAPT2 rules are missing. Preserve the existing up-to-date rule registration and avoid repeated resource linking after repair.

Cover deletion-only and Java-only R8 recovery, AAPT2-rooted Java classes and a layout constructor, no-op resource/Java/dex builds, and disabled-link/library/design-time exclusions.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The recovery logic and comprehensive regression coverage are sound; only a minor formatting suggestion remains.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Repairs missing AAPT2 keep rules in damaged incremental build caches by forcing resource relinking.

Changes:

  • Invalidates packaged resources when expected keep rules are missing.
  • Adds regression coverage for recovery and excluded configurations.
File Description
Xamarin.Android.Common.targets Triggers AAPT2 relinking when keep rules are absent.
IncrementalBuildTest.cs Tests rule regeneration, R8 retention, and subsequent incrementality.

Comment thread src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Outdated
simonrozsival and others added 2 commits October 1, 2026 21:33
Include the upstream trimmable typemap legacy-scan fix from #12976 while preserving AAPT2 damaged-cache recovery and incremental keep-rule registration.

Co-authored-by: Copilot App <[email protected]>
Address the review convention without changing the recovery condition or packaged-resource path.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival

Copy link
Copy Markdown
Member Author

@dalexsoto review

Comment thread src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recovery invalidates only packaged resources when expected AAPT2 rules are missing, then uses the existing link/configuration path to restore them. Although _CreateBaseApkInputs always runs, the !Exists('$(_Aapt2ProguardRules)') guard prevents deletion once repair has restored the rules, preserving settled-build incrementality and the existing surviving-rule registration. No current blocking issue remains.

@simonrozsival
simonrozsival merged commit f83e334 into main Oct 3, 2026
44 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-aapt2-keep-rule-recovery branch October 3, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants