Skip to content

[Microsoft.Android.Sdk.TrimmableTypeMap] Honor component JNI names - #13147

Merged
simonrozsival merged 5 commits into
mainfrom
simonrozsival-android-issue-13143
Oct 28, 2026
Merged

simonrozsival merged 5 commits into
mainfrom
simonrozsival-android-issue-13143

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Fixes: #13143

NativeAOT publishing fails when a Java peer constructor references a component with an explicit Java name, such as [Service(Name = "example.media.ControlsService")]. The component's wrapper uses that name, but constructor signature discovery computes a CRC64 name instead. The generated BoundServiceBinder.java consequently references a nonexistent class in its constructor and native constructor declaration, producing error: cannot find symbol.

Update Microsoft.Android.Sdk.TrimmableTypeMap.JavaPeerScanner.GetJniObjectDescriptor() to consult the pre-indexed explicit component name after [Register] and before the CRC64 fallback. This aligns constructor and exported object/array signatures with wrapper naming without changing registration precedence or unnamed-component behavior.

Also distinguish generated top-level wrappers from actual nested Java types when emitting source references. A wrapper named Outer$NamedComponent must retain $ in constructor, method, field, inheritance, and throws references; existing nested types such as android.graphics.Bitmap.Config must still use dots. Track the generated wrapper names during source generation, and preserve top-level dollar identifiers in Application/Instrumentation deferred registration too.

Add TrimmableTypeMapBuildTests.Build_ComponentNameIsUsedInSignatures, a build regression parameterized with TestCaseSource over all six component attributes: Activity, Service, BroadcastReceiver, ContentProvider, Application, and Instrumentation. Each fixture supplies a valid component implementation, including required overrides, attribute arguments, and activation constructors. The test compiles and packages real Release/android-arm64 applications using CoreCLR and NativeAOT, with the named component either in the app or in a referenced library, and with simple or dollar-containing explicit names: 48 independently reported cases. Shared assertions verify the final generated wrapper and binder source, including constructor, scalar/array export, and exported-field references. DEX assertions check the packaged component and constructor/export descriptors after javac runs. A Bitmap.Config export verifies that actual nested Java types retain dotted source syntax and dollar-containing binary descriptors. No synthetic assembly-metadata fixtures remain.

Validation

  • make prepare and make leeroy — passed during initial validation; complete local SDK build, including extra API bindings and local workload configuration.
  • make all — passed for the final dollar-name fix. Also passed after temporarily removing the original descriptor fix, and again after restoring it, during earlier red/green verification of the four Service build cases.
  • ./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll -v minimal --filter 'FullyQualifiedName~Build_ComponentNameIsUsedInSignatures' — the original 4 Service cases all failed in javac without the descriptor fix, with the expected nonexistent hashed MediaControlsService references, and all 4 passed with it.
  • ./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll -v minimal --filter 'Name~Service,CoreCLR,False,DollarName' — before the source-name fix, the added dollar-name case failed in javac with package example.components.Outer does not exist, reproducing the review finding.
  • ./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' — final expanded matrix passed: 48 tests, 0 failures, 0 skips. Verified eight passing results for each of the six attributes, including both simple and dollar-containing names.
  • ./dotnet-local.sh test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -v minimal --filter 'FullyQualifiedName~TypeMap' — passed after the source-name fix: 453 tests, 0 failures, 5 skips.
  • Earlier, a clean Release/android-arm64 NativeAOT reproduction also published successfully against the rebuilt SDK without the [Register] workaround, producing signed APK and AAB files. Both the original failing and fixed reproductions used the same available 11.0.0-rc.2.26475.137 NativeAOT runtime/ILC packages.

These are host-side build regressions, not device runtime tests. No device execution was performed.

After merge, request /backport to release/11.0.1xx as requested in review.


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

NativeAOT publishing fails when a Java peer constructor references a
component with an explicit name, such as [Service(Name = "...")].  The
component wrapper uses that name, but the constructor signature uses a
CRC64-generated name.  javac reports "error: cannot find symbol" for
MediaControlsService in BoundServiceBinder.java's constructor and native
constructor declaration.

Resolve indexed component names in
Microsoft.Android.Sdk.TrimmableTypeMap.JavaPeerScanner.GetJniObjectDescriptor()
before the CRC64 fallback, retaining Register attribute precedence.  This
keeps constructor and exported object/array signatures consistent with
wrapper generation.

Add regressions for all six component attributes, Register precedence,
unnamed components, and cross-assembly references scanned before the
component assembly.  Verify both JNI signatures and generated Java.

Fixes: #13143

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

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 fix preserves naming precedence, has targeted regression coverage, and leaves no identified blocking issues.

0 open findings

What changed in this PR

Fixes #13143 by aligning JNI signatures with explicit component wrapper names, preventing NativeAOT Java compilation failures.

Changes:

  • Honors component names after [Register], preserving the CRC64 fallback.
  • Adds nine regression cases covering component attributes, naming precedence, cross-assembly references, and generated Java signatures.
File Description
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerScanner.cs Resolves explicit component names in JNI descriptors and updates documentation.
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​TrimmableTypeMapComponentSignatureTests.cs Adds metadata and Java-generation regression coverage.

🧠 Review effort: Balanced

@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • azcliprod.blob.core.windows.net

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "azcliprod.blob.core.windows.net"

See Network Configuration for more information.

Generated by Android PR Reviewer for #13147

@github-actions github-actions Bot 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.

❌ Reject — 1 error, 0 warnings, 0 suggestions.

The normal explicit-name precedence and cross-assembly regression coverage are strong. However, component names containing $ now produce Java signature references that do not match the generated wrapper class, causing Java compilation to fail; details are in the inline comment.

CI is not complete: Android Tools tests and the Linux build passed, while the macOS and Windows build lanes remain in progress.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • azcliprod.blob.core.windows.net

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "azcliprod.blob.core.windows.net"

See Network Configuration for more information.

Generated by Android PR Reviewer for #13147 · copilot · gpt56 · 140.1 AIC · ⌖ 11.2 AIC · ⊞ 26.4K
Comment /review to run again

Replace synthetic assembly-metadata fixtures with a build regression for
an explicitly named service referenced by a binder.  Compile and package
real C# projects using CoreCLR and NativeAOT, with both same-assembly and
project-reference variants.

Verify the service and scalar/array constructor and export signatures in
the generated DEX rather than inspecting scanner models.  All four cases
fail in javac without the name-resolution fix and pass with it.

Fixes: #13143

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

@jonathanpeppers jonathanpeppers 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.

We should also comment /backport to release/11.0.1xx after merge.

simonrozsival and others added 3 commits October 14, 2026 23:34
Parameterize the component-signature build regression with TestCaseSource
for Activity, Service, BroadcastReceiver, ContentProvider, Application,
and Instrumentation.  Supply valid component implementations, required
attribute arguments, and activation constructors for each case.

Share the binder, build, and DEX assertions across all six attributes,
both runtimes, and both assembly layouts.  All 24 Release/android-arm64
build cases pass against the locally built SDK.

Co-authored-by: Copilot App <[email protected]>
Generated Java wrappers are top-level classes even when an explicit
component name contains '$'.  Converting every '$' into '.' makes
constructor and exported method references name a nonexistent enclosing
type, so javac rejects the generated binder.

Track generated wrapper names when emitting Java source.  Preserve '$'
for these top-level identifiers in parameters, returns, fields, base
types, interfaces, and throws clauses, while retaining source-style
nesting for existing Java types.  Preserve the same identifiers in
Application and Instrumentation deferred registration.

Extend the component build regression with simple and dollar-containing
names for all six attributes, both runtimes, and both assembly layouts.
Assert final wrapper and binder source as well as packaged descriptors,
including a Bitmap.Config control for actual Java nesting.

The dollar-named Service case fails in javac before this change.  With
the rebuilt SDK, all 48 build cases pass; standalone typemap coverage
passes 453 tests with 5 skips.

Co-authored-by: Copilot App <[email protected]>
@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 27, 2026
@simonrozsival
simonrozsival enabled auto-merge (squash) October 27, 2026 15:10
@simonrozsival

Copy link
Copy Markdown
Member Author

@dalexsoto review

@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.

Reviewed all 6 changed scanner, generator and build-test files, the production name-propagation paths and the complete 48-case build-test matrix as source, including a separate final blocker search.

Component JNI names preserve Register precedence and distinguish literal dollar names from real nested types across the scanner, generator and build paths. The earlier dollar-name concern is fixed and no independent high-confidence blocker remains.

This is a bounded static-source review, not an executed build, runtime or produced-output certification.

@simonrozsival
simonrozsival merged commit 097fd4f into main Oct 28, 2026
41 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-android-issue-13143 branch October 28, 2026 10:54
@simonrozsival

Copy link
Copy Markdown
Member Author

/backport to release/11.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

@simonrozsival backporting to release/11.0.1xx failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 097fd4f7eb6cab27a798e04254ac838c9e8d0369

Auto-merging src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs
CONFLICT (content): Merge conflict in src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs
Auto-merging src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerInfo.cs
Auto-merging src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs
Auto-merging src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs
Auto-merging src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs
CONFLICT (content): Merge conflict in src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs
error: could not apply 097fd4f7e... [Microsoft.Android.Sdk.TrimmableTypeMap] Honor component JNI names (#13147)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: [Microsoft.Android.Sdk.TrimmableTypeMap] Honor component JNI names
Applying: [tests] Exercise component JNI names through Android builds
Using index info to reconstruct a base tree...
M	src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs
CONFLICT (content): Merge conflict in src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 [tests] Exercise component JNI names through Android builds
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

jonathanpeppers pushed a commit that referenced this pull request Oct 29, 2026
…13306)

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]>
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.

.NET 11 RC2 MAUI app fails to compile (NativeAOT) with MAUI Community Toolkit

4 participants