Skip to content

[TrimmableTypeMap] JCW generation is not trimming-aware (NativeAOT emits JCWs for framework types illink removes) #11767

Description

@simonrozsival

Summary

On the NativeAOT TrimmableTypeMap build path, Java Callable Wrapper (JCW) generation is metadata-driven, not usage/trimming-aware. The scanner emits a JCW for every [Register]/Java-peer type it finds (JavaPeerScanner), regardless of whether ILC will trim that type. On the CoreCLR/illink path, unused framework types are removed before JCW generation, so their JCWs (and any associated lint/build warnings) never appear.

Impact

NativeAOT builds emit extra Java sources and warnings for framework types that are unused by the app. Example: Xamarin.Android.Net.ServerCertificateCustomValidator produces ServerCertificateCustomValidator_TrustManager.java, which trips XA0102 [CustomX509TrustManager] lint. illink removes this type on CoreCLR, so the warning does not occur there.

This is the reason the following Xamarin.Android.Build.Tests warning assertions are currently skipped on NativeAOT (with a reference to this issue):

  • BuildTest.CheckLintErrorsAndWarnings (XA0102 assertion)

Proposed work

Make JCW generation trimming-aware so NativeAOT only generates wrappers for types that survive trimming (e.g. integrate ILC's reachability, or run JCW generation against a trimmed view of the app). Once done, re-enable the skipped NativeAOT warning assertions.

Tracked as a follow-up to PR #11617.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIssues that need to be assigned.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions