[TrimmableTypeMap] Normalize dots to slashes in [Register] attribute JNI names - #10947
Merged
Conversation
The [Register] attribute on types in Android app project templates uses Java class name format with dots (e.g., 'com.xamarin.myapp.MainActivity') but the JCW generator expects JNI format with slashes. This caused JcwJavaSourceGenerator.GetOutputFilePath to throw ArgumentException 'contains invalid character .' when building apps with trimmable typemaps. Normalize dots to slashes in ParseRegisterInfo when reading the [Register] attribute's JNI name. This matches how component attribute Name properties are already normalized in the same file. Fixes #10946 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
simonrozsival
requested review from
grendello and
jonathanpeppers
as code owners
March 16, 2026 10:26
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the TrimmableTypeMap scanner to normalize dot-separated [Register] JNI names into the slash-separated form used elsewhere in the pipeline, aligning behavior with common Android template-style [Register("com.example.MyActivity")] usage.
Changes:
- Normalize
[Register]attributeJniNamevalues by converting.to/during attribute parsing. - Add a new test fixture type using dot-format
[Register]. - Add a scanner unit test asserting dot-format register names are normalized to slashes for both
JavaNameandCompatJniName.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/TestTypes.cs | Adds a fixture type with a dot-format [Register] name to validate normalization behavior. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Scanner/JavaPeerScannerTests.cs | Adds a unit test asserting dot-format register names are normalized to slash-format in scan results. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/AssemblyIndex.cs | Implements normalization (. → /) when parsing [Register] attribute JNI names. |
The fixture now mirrors the real project template: [Register] with dot-format name + [Activity] with Label and MainLauncher, matching Tests/Xamarin.ProjectTools/Resources/DotNet/MainActivity.cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Replace('.', '/') was applied in ParseRegisterInfo() which is shared
between type-level and method-level [Register] attributes. This broke
method JNI names like '.ctor' which became '/ctor', causing 5954 marshal
methods and Java constructors to be unmatched in the integration tests.
Move the normalization to the type-level call site in ParseAttributes()
where it only affects type JNI names (e.g. 'com.example.MainActivity'
→ 'com/example/MainActivity').
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers
approved these changes
Mar 16, 2026
jonathanpeppers
left a comment
Member
There was a problem hiding this comment.
There are some flaky test failures we can ignore:
System.Net.Http.HttpRequestException : The SSL connection could not be established, see inner exception.
----> System.IO.IOException : Received an unexpected EOF or 0 bytes from the transport stream.
I just merged another change in main, to maybe see if these stop happening.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #10946
Part of #10800
Summary
The
[Register]attribute on types in Android app project templates uses Java class name format with dots (e.g.,com.xamarin.myapp.MainActivity) but the JCW generator expects JNI format with slashes (com/xamarin/myapp/MainActivity). This causedJcwJavaSourceGenerator.GetOutputFilePathto throwArgumentExceptionwhen building apps with_AndroidTypeMapImplementation=trimmable.Fix
Normalize dots to slashes in
AssemblyIndex.ParseRegisterInfo()when reading the[Register]attribute's JNI name. This matches how component attributeNameproperties are already normalized in the same file (lines 102, 113).One-line change:
JniName = jniName→JniName = jniName.Replace ('.', '/')Test
Added a test fixture type
DotFormatActivitywith[Register ("com.example.dotformat.DotActivity")]and a test that verifies the scanner normalizes it tocom/example/dotformat/DotActivity.