[Microsoft.Android.Build.Tasks] Move R8 remapping task to modern assembly - #12844
Open
simonrozsival wants to merge 1 commit into
Open
simonrozsival wants to merge 1 commit into
simonrozsival wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
A concrete correctness gap in MetadataRawColumns.GetExportedTypeDefinitionId() (missing row-number validation) should be fixed before merging to avoid confusing failures on malformed metadata.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
What changed in this PR
This PR relocates the R8 mapping + JNI rewrite subsystem (and related tests) into Microsoft.Android.Build.Tasks, wiring the SDK targets to load GenerateR8JniRemapping from the modern task assembly while keeping behavior consistent with the parent PR.
Changes:
- Switched
Microsoft.Android.Sdk.R8JniRemapping.targetsto loadMicrosoft.Android.Tasks.GenerateR8JniRemappingfromMicrosoft.Android.Build.Tasks.dllusing the existing Full/CoreUsingTaskpattern. - Added/ported JNI remapping + assembly-rewrite utilities (including NativeAOT object scanning via ELF) into
src/Microsoft.Android.Build.Tasks/Utilities/JniRemappingand updated/added focused unit tests. - Updated build/test projects and packaging to reference/copy the modern task assembly dependencies (including
ELFSharp.dll).
| File | Description |
|---|---|
| tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj | Links R8Mapping.cs for net10-compatible device integration build usage. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests.csproj | Adds a project reference to Microsoft.Android.Build.Tasks for integration coverage. |
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.R8JniRemapping.targets | Loads GenerateR8JniRemapping from the modern task assembly and updates task assembly path normalization. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/R8Mapping.cs | Minor lookup/nullable adjustments in mapping logic. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/NativeResourceSectionCopier.cs | Adds PE Win32 resource-section relocation helper for rebuilt assemblies. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/NativeAotJniRetention.cs | Adds NativeAOT ELF-based retention scanning to select required mapping entries. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/MetadataRawColumns.cs | Adds raw metadata-table column readers for columns not exposed by MetadataReader. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/MetadataEncoding.cs | Adds ECMA-335 compressed integer encode/decode helpers for blob rewriting. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/LdstrRewriter.cs | Adds ldstr classification/rewriting for JNI-bearing literal patterns. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/JniRewritePlanner.cs | Adds “plan” pass to discover exact metadata/IL changes needed for rewrite. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/JniRewritePlan.cs | Adds storage for planned CA/US/FieldRVA replacements keyed by use site. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/JniRewriteException.cs | Adds dedicated exception type for rewrite failures/malformed inputs. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/JniDescriptorText.cs | Adds JNI descriptor parsing/rewriting helpers (source ↔ token conversions). |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/JniAssemblyRewriter.cs | Adds top-level rewrite/scan entrypoints for rebuilding managed assemblies. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/IlOpcodeTable.cs | Adds minimal IL operand-size table used by the IL scanner. |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/FieldRvaTable.cs | Adds FieldRVA reader/decoder for mapped field data (incl. UTF-8 JNI data). |
| src/Microsoft.Android.Build.Tasks/Utilities/JniRemapping/CustomAttributeStringRewriter.cs | Adds targeted fixed-string rewriting for custom attribute value blobs. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Utilities/JniRemapping/R8MappingTests.cs | Adds unit tests validating mapping parsing/lookup behavior. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Utilities/JniRemapping/NativeResourceSectionCopierTests.cs | Adds unit tests validating resource-section relocation and corruption handling. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Utilities/JniRemapping/LdstrRewriterTests.cs | Adds unit tests for ldstr rewriting across supported literal forms. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Utilities/JniRemapping/JniFixtureBuilder.cs | Adds PE fixture builder used by end-to-end rewrite tests. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Utilities/JniRemapping/JniDescriptorTextTests.cs | Adds unit tests for descriptor parsing/validation/conversion helpers. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Utilities/JniRemapping/AssemblyRebuilderTests.cs | Adds end-to-end assembly rebuild/edge-case tests (resources, FieldRVA, SN). |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Tasks/RewriteJniNamesForR8Tests.cs | Updates tests to reference Microsoft.Android.Tasks task namespace. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Tasks/GenerateR8JniRemappingTests.cs | Updates tests for task move and keeps aliased coverage for legacy tasks. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/JniAssemblyRewriterTypeMapTests.cs | Updates tests to use non-aliased Xamarin.Android.Tasks.JniRemapping types. |
| src/Microsoft.Android.Build.Tasks/Tasks/RewriteJniNamesForR8.cs | Moves task to Microsoft.Android.Tasks namespace and uses invariant formatting for errors. |
| src/Microsoft.Android.Build.Tasks/Tasks/GenerateR8JniRemapping.cs | Moves task to Microsoft.Android.Tasks namespace and normalizes string.Format culture usage. |
| src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj | Adds ELFSharp dependency, enables unsafe blocks, and links shared localized resources. |
| build-tools/installers/create-installers.targets | Ensures ELFSharp.dll is included in installer MSBuild payload. |
Comment on lines
12
to
16
| <TargetFramework>$(DotNetTargetFramework)</TargetFramework> | ||
| <RootNamespace>Microsoft.Android.Tasks</RootNamespace> | ||
| <Nullable>enable</Nullable> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| <WarningsAsErrors>Nullable</WarningsAsErrors> |
simonrozsival
force-pushed
the
simonrozsival-move-r8-remapping-tasks
branch
from
September 21, 2026 14:26
12ec1e8 to
4eca0b9
Compare
simonrozsival
force-pushed
the
simonrozsival-move-r8-remapping-tasks
branch
from
September 21, 2026 14:29
4eca0b9 to
9d74331
Compare
simonrozsival
removed this pull request from stack #12845
September 21, 2026 14:31
simonrozsival
added this pull request to stack #12850
September 21, 2026 14:31
This was referenced Sep 21, 2026
simonrozsival
added a commit
that referenced
this pull request
Sep 21, 2026
## Summary Remove the experimental build-time managed-assembly rewriting approach for R8 so any future assembly-rewriting design can start from a clean foundation. This cleanup is related to #12535 and the original prototype in #12575. ## What this PR undoes This removes the managed rewriting implementation developed across the R8 obfuscation stack: - #12629 added the PE metadata rebuild substrate. - #12630 added managed JNI metadata rewriting from R8 mappings. - #12631 added rewriting for generated trimmable type-map assemblies. - #12632 and #12634 integrated and tested that rewriting approach for CoreCLR and NativeAOT. Concretely, this PR removes the rewrite task, rewrite-only metadata/IL utilities, dedicated tests and fixtures, and the XA4325/XA4326 resources and documentation. The intent is to abandon this implementation rather than preserve an unused rewriting stack that a future design would need to work around. ## What remains in place - The generic `R8Mapping` parser introduced in #12628 remains, along with its tests and the `MSBuildDeviceIntegration` consumer. It is independently useful for reading R8 mapping files. - The ordinary R8 configuration and `private-members` obfuscation/optimization policy from #12668 remain unchanged. This PR does **not** disable R8 or remove private-member obfuscation. - Existing D8/R8 packaging, ProGuard rule handling, and non-rewriting build behavior remain unchanged. - Runtime remapping remains active as the stacked follow-up work in #12847, #12848, #12692, and #12844. Those PRs implement the alternative opt-in strategy without managed assembly rewriting and are not part of this cleanup diff. We may revisit managed assembly rewriting in .NET 12 based on customer feedback and performance data, but with a fresh design rather than this implementation. ## Validation - Built `Xamarin.Android.Build.Tasks` - Ran `Microsoft.Android.Build.Tasks.Tests` - Ran `Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests` - Built `MSBuildDeviceIntegration` - Ran focused `R8MappingTests`
simonrozsival
force-pushed
the
simonrozsival-move-r8-remapping-tasks
branch
from
September 21, 2026 20:49
9d74331 to
3a222f8
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
simonrozsival
force-pushed
the
simonrozsival-move-r8-remapping-tasks
branch
from
September 22, 2026 13:22
3a222f8 to
1fe751e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR is stacked on and depends on #12692. That parent is built on the focused lower chain #12846, #12847, and #12848.
This final layer is only a task-assembly boundary change for the runtime-R8 remapping producer. It moves
GenerateR8JniRemappingand the .NET-only helpers it directly requires intoMicrosoft.Android.Build.Tasks:JniRemappingAssemblyScannerR8MappingJniDescriptorTextNativeAotJniRetentionThe generic runtime table producer remains in
Xamarin.Android.Build.Tasks:GenerateJniRemappingNativeCodeandJniRemappingNativeCodeGeneratorare unchanged and continue to serve both MAM and R8 remapping.The relocation also:
GenerateR8JniRemappingfrom the modern assembly using the existing Full/CoreUsingTaskpatternELFSharp.dllbeside the modern task assembly undertools/netMSBuildDeviceIntegrationcompatible by linkingR8Mapping.csinstead of referencing the net11 task projectMergeRemapXmlandGenerateJniRemappingNativeCodeThis PR does not restore or relocate the removed managed assembly rewriter, rewrite planners/rebuilders, rewrite-only tests, or
XA4325/XA4326behavior.Validation
Microsoft.Android.Build.TasksbuildXamarin.Android.Build.TasksbuildMSBuildDeviceIntegrationproject buildtools/net/ELFSharp.dll