Skip to content

[xabt] Keep AAPT2 rules under the captured working directory - #12975

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-aapt-rules-investigation
Oct 2, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-aapt-rules-investigation

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Fixes: #12942

Clean multi-project builds using $(AndroidLinkTool)=r8 and $(TrimMode)=full can silently lose AAPT2 keep rules and produce startup ClassNotFoundException failures. <Aapt2Link/> yields its MSBuild node, allowing another project request to change the process current directory while the task is still running. The merged ProguardRuleOutput write used a relative path, unlike the per-manifest rules. A misplaced merged file is then omitted by downstream Exists() guards and never passed to R8.

Resolve the merged rules output against the task's captured working directory with the existing GetFullPath() helper. Apply the same anchoring to manifest loading and manifest/flag timestamp checks in <Aapt2Link/>. These additional paths preserve absolute inputs; standard callers already supply an absolute manifest and do not currently set the flag property. Leave <Aapt2Compile/> and <Aapt2LinkAssetPack/> unchanged because their shipped invocations do not enable yielding. This addresses the clean-build directory race separately from the incremental rules-registration fix in #12950.

Update Nightly Fix Finder's General Mistakes category with a bounded filesystem-operation scan and guidance that requires checking actual shipped invocations, yielding defaults/property wiring, and relative-path reachability. Already anchored paths and hypothetical future-yielding hardening are excluded.

Validation: Bash syntax and scanner execution passed; strict workflow compilation produced no generated-content changes. Source-extracted manifest/timestamp probes reproduced failures after changing the current directory and passed with the fix, covering relative/absolute paths, timestamp ordering, and missing/empty flags. No in-tree regression test was added, and the full Android build/task suite was not run because the local repository-built SDK is unavailable.

Clean multi-project builds with R8 and full trimming can silently omit
AAPT2 keep rules, resulting in ClassNotFoundException at startup.  While
<Aapt2Link/> yields its MSBuild node, another project request can change
the process current directory.  The merged ProguardRuleOutput write uses
a relative path, so subsequent Exists() guards can omit the misplaced
file from @(ProguardConfiguration).

Resolve the merged rules output against the task's captured directory
using its existing GetFullPath() helper.  Also anchor manifest loading
and manifest/flag timestamp checks within the same yielding task.  Leave
compile and asset-pack tasks unchanged: their shipped invocations do not
enable yielding.

Extend Nightly Fix Finder's general-mistakes category with a bounded
filesystem scan and guidance for verifying actual yielding, property
wiring, and relative-path reachability before proposing a race fix.

Fixes: #12942

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

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

🟡 Changes recommended

The race fix lacks a permanent in-tree regression test.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Anchors AAPT2 filesystem operations to the task’s captured working directory, preventing keep-rule loss during concurrent builds.

Changes:

  • Resolves rule, manifest, and timestamp paths against WorkingDirectory.
  • Adds Nightly Fix Finder guidance and scanning for similar races.
File Description
Aapt2Link.cs Anchors affected paths to the captured directory.
05-general-mistakes.sh Adds race-detection guidance and candidate scanning.

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 1, 2026
@jonathanpeppers

jonathanpeppers commented Oct 2, 2026 •

Copy link
Copy Markdown
Member Author

I think the emulator disk is full on one of the failures:

/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: Performing Streamed Install
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: adb: failed to install /Users/runner/work/1/s/bin/TestDebug/net11.0-android/Mono.Android.NET_Tests-Signed.apk: 
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: Exception occurred while executing:
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.pm.PackageManagerInternal.freeStorage(java.lang.String, long, int)' on a null object reference
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at com.android.server.StorageManagerService.allocateBytes(StorageManagerService.java:3263)
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at android.os.storage.StorageManager.allocateBytes(StorageManager.java:2099)
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at android.os.storage.StorageManager.allocateBytes(StorageManager.java:2156)
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at com.android.server.pm.PackageInstallerSession.doWriteInternal(PackageInstallerSession.java:723)
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at com.android.server.pm.PackageInstallerSession.write(PackageInstallerSession.java:670)
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at android.content.pm.PackageInstaller$Session.write(PackageInstaller.java:951)
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at com.android.server.pm.PackageManagerShellCommand.doWriteSplit(PackageManagerShellCommand.java:2732)
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at com.android.server.pm.PackageManagerShellCommand.runInstall(PackageManagerShellCommand.java:1072)
/Users/runner/work/1/s/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/37.99.0-ci.pr.gh12975.0/tools/Xamarin.Android.Common.Debugging.targets(240,5): error ADB0010: 	at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerSh

Merging.

@jonathanpeppers
jonathanpeppers merged commit 22b3d81 into main Oct 2, 2026
42 of 44 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-aapt-rules-investigation branch October 2, 2026 13:34
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/backport to release/11.0.1xx

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

jonathanpeppers added a commit that referenced this pull request Oct 5, 2026
…#12989)

Clean multi-project builds with R8 and full trimming can silently omit
AAPT2 keep rules, resulting in ClassNotFoundException at startup.  While
<Aapt2Link/> yields its MSBuild node, another project request can change
the process current directory.  The merged ProguardRuleOutput write uses
a relative path, so subsequent Exists() guards can omit the misplaced
file from @(ProguardConfiguration).

Resolve the merged rules output against the task's captured directory
using its existing GetFullPath() helper.  Also anchor manifest loading
and manifest/flag timestamp checks within the same yielding task.  Leave
compile and asset-pack tasks unchanged: their shipped invocations do not
enable yielding.

Extend Nightly Fix Finder's general-mistakes category with a bounded
filesystem scan and guidance for verifying actual yielding, property
wiring, and relative-path reachability before proposing a race fix.

Fixes: #12942

Co-authored-by: Jonathan Peppers <[email protected]>
Co-authored-by: Copilot App <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[R8] Aapt2 rules are silently dropped from R8 input

3 participants