Skip to content

[TrimmableTypeMap] Manifest rooting and deferred registration propagation#11097

Merged
simonrozsival merged 2 commits intodev/simonrozsival/trimmable-scanner-jcw-fixesfrom
dev/simonrozsival/trimmable-manifest-rooting
Apr 10, 2026
Merged

[TrimmableTypeMap] Manifest rooting and deferred registration propagation#11097
simonrozsival merged 2 commits intodev/simonrozsival/trimmable-scanner-jcw-fixesfrom
dev/simonrozsival/trimmable-manifest-rooting

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

@simonrozsival simonrozsival commented Apr 9, 2026

Summary

Manifest-aware rooting and deferred registration propagation for the trimmable typemap generator.

Depends on: #11096 (scanner + JCW fixes)

Changes

  • Manifest name promotion: Promote compat JNI names for manifest-rooted components so the generated JCW class name matches the manifest entry
  • Deferred registration propagation: Propagate CannotRegisterInStaticConstructor to generated managed base types of Application/Instrumentation
  • Instrumentation targetPackage: Pass package name for manifest instrumentation elements
  • XA4250 warning: Warn when manifest references a type that cannot be resolved in any scanned assembly
  • Typed logger extension: Add LogUnresolvedTypeWarning and LogRootingManifestReferencedTypeInfo to the logger interface

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 extends the trimmable typemap generator pipeline to be manifest-aware: it roots manifest-referenced components (including placeholder/substitution handling), promotes compat JNI names so generated JCW names match manifest declarations, and propagates deferred registerNatives behavior through managed base hierarchies for Application/Instrumentation types.

Changes:

  • Root manifest-referenced component types as unconditional (with placeholder resolution) and log/warn for unresolved types (XA4250).
  • Promote compat JNI names for manifest-rooted components so generated JCW class names align with manifest entries.
  • Propagate deferred registration (CannotRegisterInStaticConstructor) to generated managed base types and default instrumentation targetPackage.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TrimmableTypeMapGeneratorTests.cs Adds unit tests for manifest rooting, placeholder resolution, compat name promotion, deferred registration propagation, and unresolved-type warnings.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/ManifestGeneratorTests.cs Adds a test ensuring instrumentation defaults targetPackage to the manifest package.
src/Xamarin.Android.Build.Tasks/Tasks/GenerateTrimmableTypeMap.cs Implements new typed logger methods: XA4250 warning + info logging for manifest rooting.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Adds localized string for XA4250.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Updates generated resource accessor for XA4250.
src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs Adds manifest-rooting + placeholder prep, compat-JNI promotion, and deferred registration propagation logic.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerInfo.cs Makes several properties mutable to support post-scan manifest rooting and propagation.
src/Microsoft.Android.Sdk.TrimmableTypeMap/ITrimmableTypeMapLogger.cs Extends logger interface with unresolved-type warning + manifest-rooting info message.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ManifestGenerator.cs Passes package name into instrumentation generation and simplifies placeholder application.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ComponentElementBuilder.cs Defaults instrumentation targetPackage when missing.
Documentation/docs-mobile/messages/xa4250.md Adds documentation page for XA4250 warning.
Documentation/docs-mobile/messages/index.md Adds XA4250 to the messages index.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported

Comment on lines +195 to +208
foreach (var name in componentNames) {
if (peersByDotName.TryGetValue (name, out var peers)) {
foreach (var peer in peers.Distinct ()) {
PromoteManifestCompatibleJavaName (allPeers, peer, name);

if (deferredRegistrationNames.Contains (name)) {
peer.CannotRegisterInStaticConstructor = true;
}

if (!peer.IsUnconditional) {
peer.IsUnconditional = true;
logger?.LogRootingManifestReferencedTypeInfo (name, peer.ManagedTypeName);
}
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peers.Distinct() here relies on JavaPeerInfo record value equality/hashing, but JavaPeerInfo now has mutable properties (e.g., JavaName, IsUnconditional, CannotRegisterInStaticConstructor) that are modified inside this loop. Mutating keys used in Distinct()/HashSet can lead to incorrect de-duplication and unpredictable behavior. Consider de-duping by reference (custom comparer) or avoid Distinct() and instead track processed peers in a separate HashSet<JavaPeerInfo> using reference equality.

Copilot uses AI. Check for mistakes.
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from d64ece1 to 6ccb7ca Compare April 9, 2026 08:23
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-manifest-rooting branch 2 times, most recently from 2b22bc6 to 3b1083e Compare April 9, 2026 08:28
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch 2 times, most recently from 3aa9b44 to 8fd237a Compare April 9, 2026 08:30
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-manifest-rooting branch 2 times, most recently from 23890de to 6ac587c Compare April 9, 2026 08:32
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from 8fd237a to b82f717 Compare April 9, 2026 08:32
@simonrozsival simonrozsival added trimmable-type-map copilot `copilot-cli` or other AIs were used to author this labels Apr 9, 2026
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from b82f717 to 0768a52 Compare April 9, 2026 14:49
…tion

- Manifest name promotion: promote compat JNI names for manifest-rooted
  components so the generated JCW class name matches the manifest entry
- Deferred registration propagation: propagate CannotRegisterInStaticConstructor
  to generated managed base types of Application/Instrumentation
- Instrumentation targetPackage: pass package name for manifest
  instrumentation elements
- XA4250 warning: warn when manifest references a type that cannot be
  resolved in any scanned assembly
- NestedAssembly for UTF-8 helpers: fix FieldAccessException from
  NestedPrivate visibility

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-manifest-rooting branch from 6ac587c to 3b2d707 Compare April 9, 2026 14:56
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival marked this pull request as draft April 10, 2026 05:42
@simonrozsival simonrozsival marked this pull request as ready for review April 10, 2026 05:42
@simonrozsival simonrozsival merged commit 682ebac into dev/simonrozsival/trimmable-scanner-jcw-fixes Apr 10, 2026
2 of 3 checks passed
@simonrozsival simonrozsival deleted the dev/simonrozsival/trimmable-manifest-rooting branch April 10, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants