Skip to content

[Microsoft.Android.Build.Tasks] Add typemap rule generators - #12822

Open
simonrozsival wants to merge 1 commit into
mainfrom
simonrozsival-typemap-proguard-foundation
Open

simonrozsival wants to merge 1 commit into
mainfrom
simonrozsival-typemap-proguard-foundation

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Layer 1 of 6 splitting #12821; build activation comes in later layers.

Establish a shared retained-Java-key contract so the runtime-specific extractors can feed the same ProGuard generators without duplicating rule generation. This is a focused slice of the validated source at 87bd3f8a8b512859339e5446c1f86709a6c28c3b, based on main at d63fe4c9f8cf8def6049c9415bb0abf4269ee0f5.

Scope and contract

  • Add canonical JNI class-name and alias-key utilities. The shared interchange format is sorted, unique JNI class names, UTF-8 without BOM, with LF line endings.
  • Add <GenerateTypeMapProguardConfiguration/>, which unions canonical keys and emits only -keep class rules. Reject invalid names/rule injection and missing inputs before overwriting output; valid empty inputs produce empty output.
  • Add <GenerateTypeMapMemberProguardConfiguration/>, which keeps all members of retained classes. This is not precise-method inference.
  • Add shared XA4327/XA4328 diagnostics and documentation while preserving XA4319/XA4320/XA4321 and the newer base localization changes.
  • Add the standalone production-task reference, minimal build engine, six generator unit-test methods, and the final-source NUnit fixture.

No extractors, target imports, UsingTask activation, R8 policy changes, runtime changes, or DGML removal are included. The standalone TypeMapProguardTests fixture is intentionally a generator-only subset; later layers add its adapter/target/configuration coverage.

Validation

dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj -v minimal --filter 'FullyQualifiedName~TypeMapProguardTests'

15 passed, 0 failed, 0 skipped, compiling the actual modern production task project and its source-linked shared resources.

The focused NUnit command was also attempted. Its existing legacy Xamarin.Android.Build.Tasks project reference requires the missing bin/BuildDebug/net10.0/xa-prep-tasks.dll (GitBlame/GitCommitHash, MSB4062) in this clean worktree. The unchanged frozen-source fixture is retained; no full SDK/bootstrap build or test-project infrastructure changes were made.

git diff --check passes. Complete extracted files match the frozen source byte-for-byte; retained standalone test/helper methods match the frozen source. The diff is additive only: 14 files, 546 insertions.

Establish the shared retained-key contract before adding the runtime
extractors and R8 pipeline wiring.  Layer 1 of 6 splitting #12821
uses the frozen source at 87bd3f8.

Add canonical JNI key helpers and deterministic UTF-8/LF generators
for class-only keep rules and all-member rules scoped to retained
classes.  Reject invalid records before overwriting existing output.
Add shared XA4327/XA4328 diagnostics without retiring the active
legacy diagnostics, plus isolated production-task unit coverage.

No build pipeline behavior changes; activation comes in later layers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 18, 2026 14:55
@simonrozsival simonrozsival added the r8-rules Typemap-derived ProGuard and R8 rules label Sep 18, 2026

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 generator mishandles some failure diagnostics and does not consistently follow the task error-state contract.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

Adds shared typemap key utilities and ProGuard generator tasks for later runtime-specific adapters.

Changes:

  • Generates sorted class-only and member-preserving ProGuard rules.
  • Adds canonical key helpers and localized XA4327/XA4328 diagnostics.
  • Adds production-task references, tests, and documentation.
File Description
src/​Microsoft.Android.Build.Tasks/​Tasks/​GenerateTypeMapProguardConfiguration.cs Core rule generator
src/​Microsoft.Android.Build.Tasks/​Tasks/​GenerateTypeMapMemberProguardConfiguration.cs Member rule variant
src/​Microsoft.Android.Build.Tasks/​Utilities/​TypeMapClassName.cs JNI class-name extraction
src/​Microsoft.Android.Build.Tasks/​Utilities/​TypeMapKey.cs Alias normalization
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.resx New diagnostics
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.Designer.cs Generated resource accessors
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​TypeMapTaskBuildEngine.cs Minimal test build engine
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj Production task reference
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TypeMapProguardTests.cs Generator tests
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​GenerateTypeMapProguardConfigurationTests.cs NUnit coverage
Documentation/​docs-mobile/​messages/​xa4327.md XA4327 documentation
Documentation/​docs-mobile/​messages/​xa4328.md XA4328 documentation
Documentation/​docs-mobile/​messages/​index.md Message index entries
Documentation/​docs-mobile/​TOC.yml Documentation navigation
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file

foreach (var name in classes) {
WriteClassRule (writer, name);
}
} catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException || ex is DecoderFallbackException) {
string currentFile = "";
try {
if (TypeMapKeyFiles.Length == 0) {
Log.LogCodedError ("XA4328", Properties.Resources.XA4328, "", Properties.Resources.XA4328_NoInputs);
try {
if (TypeMapKeyFiles.Length == 0) {
Log.LogCodedError ("XA4328", Properties.Resources.XA4328, "", Properties.Resources.XA4328_NoInputs);
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r8-rules Typemap-derived ProGuard and R8 rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants