Skip to content

[TrimmableTypeMap] Normalize dots to slashes in [Register] attribute JNI names - #10947

Merged
jonathanpeppers merged 3 commits into
mainfrom
dev/simonrozsival/fix-jni-name-dots
Mar 16, 2026
Merged

[TrimmableTypeMap] Normalize dots to slashes in [Register] attribute JNI names#10947
jonathanpeppers merged 3 commits into
mainfrom
dev/simonrozsival/fix-jni-name-dots

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

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 caused JcwJavaSourceGenerator.GetOutputFilePath to throw ArgumentException when 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 attribute Name properties are already normalized in the same file (lines 102, 113).

One-line change: JniName = jniNameJniName = jniName.Replace ('.', '/')

Test

Added a test fixture type DotFormatActivity with [Register ("com.example.dotformat.DotActivity")] and a test that verifies the scanner normalizes it to com/example/dotformat/DotActivity.

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>
Copilot AI review requested due to automatic review settings March 16, 2026 10:26

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.

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] attribute JniName values 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 JavaName and CompatJniName.

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.

simonrozsival and others added 2 commits March 16, 2026 11:37
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 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.

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.

@jonathanpeppers
jonathanpeppers merged commit d6849dd into main Mar 16, 2026
5 of 6 checks passed
@jonathanpeppers
jonathanpeppers deleted the dev/simonrozsival/fix-jni-name-dots branch March 16, 2026 19:51
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TrimmableTypeMap] JCW generator crashes on component types without explicit Name property

3 participants