dotnet / dotnet/android

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

Open
#11,767 0 comments 0 reactions 0 assignees View on GitHub
needs-triage
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 20h
Merged PRs (30d)
257

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the NativeAOT TrimmableTypeMap path and JavaPeerScanner to trace how [Register]/Java-peer types become JCWs before trimming information is applied. Compare this with the CoreCLR/illink path, then inspect Xamarin.Android.Build.Tests.BuildTest.CheckLintErrorsAndWarnings; done means trimmed framework types no longer generate JCWs and the skipped XA0102 assertion can be re-enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system, compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.