Skip to content

[tests] Cover R8 bound Java field preservation - #13248

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-r8-field-test-on-main
Oct 26, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-r8-field-test-on-main

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Add the test coverage from #13239 to main. These tests protect managed JNI field access from R8 field removal, renaming, and type narrowing. Related issue: #13159.

The static-field test builds a trimmed CoreCLR Release app with Xamarin.AndroidX.Core 1.19.0.1 and checks ACTION_COLLAPSE in DEX output with obfuscation disabled and with private-members. The instance-field test binds a Java int field with values 0, 1, and 2, keeps its Java reader live, and checks that R8 preserves its I descriptor instead of narrowing it to B.

Add exact field class/name/type matching to the shared DEX test helper and unit coverage for that matching. Main already preserves these fields through its typemap member rules, so this PR contains no production or documentation changes and does not assert the release-specific generated rule.

Rebased on main at c44b901. Local validation after the rebase, using the local SDK:

  • dotnet-local.cmd build Microsoft.Android.slnx -t:BuildDotNet -nodeReuse:false -v:minimal -bl:bin\BuildDebug\sdk-rebase.binlog — passed; 92 warnings, 0 errors.
  • dotnet-local.cmd test bin\TestDebug\net10.0\Xamarin.Android.Build.Tests.dll --filter "FullyQualifiedName~DexUtilsTests|Name~R8PreservesAccessibilityActionField|Name~R8PreservesInstanceIntFieldType" --logger "console;verbosity=normal" --logger "trx;LogFileName=r8-fields-rebase.trx" --results-directory C:\Users\jopepper\.copilot\session-state\4f444992-9269-4af2-be93-975076a809d0\files\TestResults — passed; 17 tests, 0 failed, 0 skipped (31.6117 seconds).

Test environment: TEST_ANDROID_JDK_PATH=D:\android-toolchain\jdk-25, TEST_ANDROID_SDK_PATH=D:\android-toolchain\sdk, TEST_ANDROID_NDK_PATH=D:\android-toolchain\ndk.


Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

Port the regression tests from 5485ae3 to main. Check ACTION_COLLAPSE in DEX output for both obfuscation modes without asserting release-specific keep rules.

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

Copilot-Session: 4f444992-9269-4af2-be93-975076a809d0
Port the test-only coverage from 2d4f358 to main. Verify the original int descriptor of a bound Java instance field after R8 optimization.

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

Copilot-Session: 4f444992-9269-4af2-be93-975076a809d0
Copilot AI balanced review requested due to automatic review settings October 23, 2026 19:14

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.

🟢 Approval recommended

The focused test-only changes preserve existing helper behavior, have no identified blocking issues, and include reported successful local build and test validation.

No open issues 🎉

What changed in this PR

Adds regression coverage for bound Java field preservation under R8, bringing the tests from #13239 to main without changing production behavior.

Changes:

  • Tests that ACTION_COLLAPSE retains its name and type with obfuscation disabled and with private-members.
  • Tests that a bound instance int field retains its DEX descriptor rather than being narrowed to byte.
  • Adds exact declaring-class, field-name, and type matching to the shared DEX helper, with unit coverage.
File Description
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.ProjectTools/​Utilities/​DexUtils.cs Shares member-matching logic between method and new field lookups.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​PackagingTest.cs Adds static and instance field preservation regression tests.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​DexUtilsTests.cs Verifies exact field matching and rejects mismatched lookup values.

Review effort: Balanced

@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@jonathanpeppers
jonathanpeppers enabled auto-merge (squash) October 26, 2026 13:34
@dalexsoto

Copy link
Copy Markdown
Member

@jonathanpeppers Not reviewing this request in this iteration: the current-head source passes found no significant issue and CI succeeded, but the explicit itemized candidate-finding/disposition ledger needed to verify the final consolidated review boundary has not yet been returned by the read-only reviewer. I will not submit a formal decision on an incomplete handoff.

@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 exact DEX field checks and R8 regression coverage preserve the existing method-matching behavior. No high-confidence blockers found in the three-file change and its material static integration.

@jonathanpeppers
jonathanpeppers merged commit e72b270 into main Oct 26, 2026
42 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-r8-field-test-on-main branch October 26, 2026 15:01
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.

3 participants