Skip to content

[release/11.0.1xx] [Microsoft.Android.Sdk.TrimmableTypeMap] Honor component JNI names - #13306

Merged
jonathanpeppers merged 1 commit into
release/11.0.1xxfrom
simonrozsival-component-jni-name-backport
Oct 29, 2026
Merged

jonathanpeppers merged 1 commit into
release/11.0.1xxfrom
simonrozsival-component-jni-name-backport

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Manual backport of #13147 (097fd4f) to release/11.0.1xx.

Fixes: #13143

An explicit component name, such as [Service(Name = "example.media.ControlsService")], names its Java wrapper correctly but previously resolved to a CRC64 name in constructor and exported signatures. This makes generated Java reference a nonexistent class and fail with cannot find symbol. Resolve explicit component names after [Register] and before the CRC64 fallback. Preserve $ in generated top-level wrapper identifiers and deferred Application/Instrumentation registration, while retaining dotted source references for actual nested Java types such as Bitmap.Config.

Release adaptations

  • Resolve the JcwJavaSourceGenerator.cs conflict by preserving this branch's native-constructor declaration behavior, while passing the generated-peer name set through signature formatting. Add the explicit System.Linq import required by this branch.
  • Resolve the TrimmableTypeMapBuildTests.cs conflict by keeping the release branch's existing Unicode tests and inserting only the component-name regressions, without bringing in unrelated main-branch tests.
  • Explicitly set AndroidTypeMapImplementation=trimmable in the new application fixture because CoreCLR still defaults to the legacy typemap on this branch. Product defaults are unchanged. Retain all 48 original build cases and their generated-source and packaged-DEX assertions; no synthetic PEReader tests are added.

Validation on this release backport

Commands below omit only TRX-output options and local log redirection.

  • make prepare — passed.
  • make leeroy — passed, including the solution build, extra API levels, and local workload configuration.
  • ./dotnet-local.sh test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/bin/Debug/net11.0/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.dll -v minimal — passed: 1,016 tests, 0 failures, 0 skips.
  • ./dotnet-local.sh test bin/TestDebug/net11.0/Microsoft.Android.Build.Tasks.Tests.dll -v minimal --filter 'FullyQualifiedName~TypeMap' — passed: 18 tests, 0 failures, 0 skips.
  • ./dotnet-local.sh test src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj -v minimal --filter 'FullyQualifiedName~Build_ComponentNameIsUsedInSignatures' — passed: all 48 cases, 0 failures, 0 skips. The TRX contains exactly the expected 48 unique combinations, including 8 passing cases for each component attribute.
  • ./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll -v minimal --filter 'FullyQualifiedName~Build_JavaTypeOnlyIdentifierStarts|FullyQualifiedName~Build_SupplementaryJavaIdentifier|FullyQualifiedName~Build_InvalidOrUnsupportedUnicodeIdentifiers' — passed: 9 existing release-specific cases, 0 failures, 0 skips.

The initial matrix invocation (./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll -v minimal --filter 'FullyQualifiedName~Build_ComponentNameIsUsedInSignatures') was stopped after revealing that CoreCLR selected the release branch's legacy typemap. The final 48-case run above passed after explicitly selecting trimmable in the fixture.

These are local host-side tests and real application builds against the freshly built release-branch SDK. No device execution was performed.


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

Backport 097fd4f from #13147 to
release/11.0.1xx.  Explicit component names must be used after Register
and before CRC64 fallback when resolving JNI object descriptors.  This
prevents generated constructor and exported signatures from referencing
nonexistent hashed classes, which caused javac cannot-find-symbol errors.

Preserve dollars in generated top-level wrapper identifiers while keeping
actual nested Java types dotted in source references and deferred
Application/Instrumentation registration.

Keep release-specific native-constructor emission and Unicode tests when
resolving conflicts.  Explicitly select the trimmable typemap in the new
build regression because CoreCLR still defaults to the legacy typemap on
this branch.  Preserve all 48 component-name build cases.

Fixes: #13143
Context: #13147

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

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.

🟡 Changes recommended

Valid generated component names such as example.components.Outer$for still trigger XA4258 because validation splits them at $, affecting constructor/export signatures and deferred Application/Instrumentation registration.

1 open issue
What changed in this PR

Backports explicit component JNI-name handling to release/11.0.1xx, aligning trimmable typemap signatures with generated Java wrappers to address #13143.

Changes:

  • Resolve component names after [Register] and before the CRC64 fallback.
  • Preserve $ in generated top-level wrapper references and deferred registration while retaining dotted references for nested Java types.
  • Add 48 build regression cases across six component attributes, two runtimes, app/library placement, and simple/dollar-containing names, explicitly selecting the trimmable typemap.
File Description
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​TrimmableTypeMapBuildTests.cs Adds component-name build tests with Java-source and packaged-DEX assertions.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​TrimmableTypeMapGenerator.cs Preserves generated wrapper names in deferred registration.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerScanner.cs Uses explicit component names when resolving JNI descriptors.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerInfo.cs Clarifies the descriptor’s role in source generation.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Generator/​JniSignatureHelper.cs Adds generated-wrapper-aware name conversion.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Generator/​JcwJavaSourceGenerator.cs Passes generated wrapper names through Java source formatting while preserving release-branch constructor behavior.

Review effort: Balanced

Comment on lines +241 to +243
// Generated wrappers are top-level classes, even when their identifiers contain '$'.
if (generatedPeerNames?.Contains (jniName) == true) {
return JniNameToJavaBinaryName (jniName);
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 29, 2026
@jonathanpeppers
jonathanpeppers merged commit 6d4cadf into release/11.0.1xx Oct 29, 2026
45 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-component-jni-name-backport branch October 29, 2026 13:27
simonrozsival added a commit that referenced this pull request Nov 4, 2026
Context: #13147
Context: #13306 (comment)

An explicit component name such as `example.components.Outer$for` is a valid top-level Java identifier, but constructor and export signatures referencing it fail with XA4258.  Application and Instrumentation wrappers with these names also fail deferred-registration validation, even without a signature referencing them.

The source generator preserves '$' in generated wrapper names after #13147, but validation still splits every source reference at '$' and rejects the resulting keyword `for`.  Pass the generated-peer name set through source-type and JNI descriptor validation so validation uses the same top-level-versus-nested distinction as source generation.  Continue checking package segments and the complete generated identifier, and retain nested-identifier validation for external Java types.

Add 58 focused regression cases covering generated and external references, invalid identifiers, deferred registration, and default-package throws clauses.  Extend the existing application-build matrix with `Outer$for`, retaining its generated-source and packaged-DEX assertions for all six component attributes, both runtimes, and same- and cross-assembly references.

Local validation passes: `make prepare`, `make leeroy`, 105 trimmable-typemap task tests, all 72 component-signature application-build cases, and six existing invalid-name diagnostic application-build cases.  No device execution is performed.

Co-authored-by: Copilot App <[email protected]>
simonrozsival added a commit that referenced this pull request Nov 5, 2026
)

Context: #13147
Context: #13306 (comment)

An explicit component name such as `example.components.Outer$for` is a valid top-level Java identifier, but constructor and export signatures referencing it fail with XA4258.  Application and Instrumentation wrappers with these names also fail deferred-registration validation, even without a signature referencing them.

The source generator preserves `$` in generated wrapper names after #13147, but validation still splits every source reference at `$` and rejects the resulting keyword `for`.  Pass the generated-peer name set through source-type and JNI descriptor validation so validation uses the same top-level-versus-nested distinction as source generation.  Continue checking package segments and the complete generated identifier, and retain nested-identifier validation for external Java types.

Add 58 focused regression cases covering generated and external references, invalid identifiers, deferred registration, and default-package throws clauses.  Extend the existing application-build matrix with `Outer$for`, retaining its generated-source and packaged-DEX assertions for all six component attributes, both runtimes, and same- and cross-assembly references.
jonathanpeppers pushed a commit that referenced this pull request Nov 10, 2026
…a identifiers (#13405)

Context: #13147
Context: #13306 (comment)

An explicit component name such as `example.components.Outer$for` is a valid top-level Java identifier, but constructor and export signatures referencing it fail with XA4258.  Application and Instrumentation wrappers with these names also fail deferred-registration validation, even without a signature referencing them.

The source generator preserves `$` in generated wrapper names after #13147, but validation still splits every source reference at `$` and rejects the resulting keyword `for`.  Pass the generated-peer name set through source-type and JNI descriptor validation so validation uses the same top-level-versus-nested distinction as source generation.  Continue checking package segments and the complete generated identifier, and retain nested-identifier validation for external Java types.

Add 58 focused regression cases covering generated and external references, invalid identifiers, deferred registration, and default-package throws clauses.  Extend the existing application-build matrix with `Outer$for`, retaining its generated-source and packaged-DEX assertions for all six component attributes, both runtimes, and same- and cross-assembly references.

(cherry picked from commit 536fa66)

### [TrimmableTypeMap] Adapt backport tests to release xUnit layout

Keep all 58 upstream regression cases in the release branch typemap test assembly, reuse its logger and internal access, and update legacy deferred-registration expectations for generated top-level identifiers.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

3 participants