Repository navigation
[Microsoft.Android.Sdk.TrimmableTypeMap] Fix Java overrides - #13242
Conversation
Fixes #13235 Ads.Lite retains a registered managed compatibility method named zza, while its Java interface only declares zzb. A registration connector does not guarantee that the method overrides a Java supertype member. Emitting @OverRide for this method makes javac reject the wrapper. Stop emitting the unconditional annotation while preserving methods and native callbacks. Add unit coverage for registration connectors and CoreCLR/NativeAOT build coverage for the package implementor and a user listener implementing only the abstract interface members. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The narrowly scoped annotation removal preserves dispatch behavior, has focused regression coverage, and has no unresolved review findings.
No open issues 🎉
What changed in this PR
Fixes #13235 by removing unconditional @Override annotations from registered callbacks generated by the trimmable typemap. This allows managed compatibility methods absent from Java supertypes to compile without changing callback dispatch.
Changes:
- Removes the annotation and updates the generator’s example and explanatory comment.
- Adds unit coverage for nonempty, empty, and null registration connectors.
- Adds CoreCLR and NativeAOT build regressions covering both package-provided and user-defined listener wrappers.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs | Adds Ads.Lite build regressions verifying both wrappers retain zza and zzb without @Override. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs | Stops emitting unconditional @Override for registered callbacks. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/GenerateTrimmableTypeMapTests.cs | Verifies annotation removal and preserved callback generation across connector variants. |
Review effort: Balanced
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
Code assessment: no blocking findings. 0 ❌ errors, 0
The implementation is appropriately scoped: managed registration metadata does not prove a matching Java supertype member exists, and removing the optional @Override annotation leaves method signatures, native declarations, registration, and dispatch unchanged. The example now matches the emitted source. Regression coverage includes nonempty/empty/null connectors and both the package implementor and a user-defined listener.
CI: All 42 checks returned for the PR head report success, including the aggregate dotnet-android check for Azure build 1645934. Direct Azure DevOps build/timeline inspection was blocked by the environment, so that independent CI verification remains incomplete; this is not a fully verified green-CI verdict. Tests were not rerun locally during this review.
Generated by Android PR Reviewer for #13242 · copilot · gpt61 · 38.8 AIC · ⌖ 7.4 AIC · ⊞ 19.3K
Comment /review to run again
| [TestCase (AndroidRuntime.NativeAOT)] | ||
| public void Build_RegisteredCompatibilityMethods_DoNotRequireJavaOverrides (AndroidRuntime runtime) | ||
| { | ||
| var proj = new XamarinAndroidApplicationProject (); |
There was a problem hiding this comment.
🤖 💡 Testing — Consider adding a CoreCLR Release case for this package-specific regression. SetRuntime(CoreCLR) leaves this project in Debug, while SetRuntime(NativeAOT) switches it to Release, so the two cases do not exercise CoreCLR's post-trim Java regeneration. A Release CoreCLR build with this listener, checking the surviving wrapper under typemap/linked-java, would cover the publish path with the actual compatibility-method metadata rather than only the untrimmed generator output.
{Rule: Bug fixes need regression tests; test the affected configuration}
Fixes #13235.
Publishing an app referencing
Xamarin.GooglePlayServices.Ads.Lite123.4.0 with the trimmable typemap fails withXAJVC0000: the generatedMediationBannerListenerImplementor.javaapplies@Overridetozza, which does not override or implement a Java supertype method. User-defined implementations of the same managed interface can fail for the same reason.Investigation
Reproduced the failure using the reported .NET SDK,
11.0.100-rc.2.26504.105, and package version. The stock Android workload available with that SDK still defaults NativeAOT to the older managed typemap, so reproduction required explicitly selecting the trimmable implementation:This failed on the
@Overrideannotation at line 78 of the generated wrapper, matching the report. Directjavaccompilation of that wrapper reproduced the same error. Publishing with Mono succeeded.Decompiling the package revealed that
Android.Gms.Ads.Mediation.IMediationBannerListenerretains a registered default compatibility method,Zza, mapped to Javazza. Inspecting the actual Java interface withjavapshowed that it declareszzb, notzza. The package's managed implementor also implementsZza, and the scanner collects the registered compatibility member for user listeners even when they implement only the abstract interface members.The generator was treating a non-null registration connector as proof that a method overrides a Java supertype member. The managed registration metadata provides no such guarantee, explaining why both wrappers fail.
Fix
Remove the unconditional
@Overrideannotation from registered callbacks rather than filtering out compatibility methods or special-casing Ads.Lite. Keep the generated methods, native declarations, and callback dispatch unchanged. Java virtual/interface dispatch does not require this annotation.Add unit coverage for nonempty, empty, and null registration connectors, plus CoreCLR and NativeAOT build regressions using the reported package and a user-defined listener. The build tests check that both the package implementor and user wrapper retain
zzaandzzbwithout the invalid annotation.Validation
make prepare— passed../dotnet-local.sh build build-tools/scripts/Prepare.proj -t:BuildExtraApiLevels -v:minimal— passed, providing the additional reference APIs needed by local workload setup.make all— passed, including local workload setup../dotnet-local.sh test bin/TestDebug/net11.0/Microsoft.Android.Build.Tasks.Tests.dll --filter 'FullyQualifiedName~TrimmableTypeMap|FullyQualifiedName~GenerateTypeMap|FullyQualifiedName~GenerateMissingTypeMapStubs'— 76 passed, 0 skipped../dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll --filter 'Name~Build_RegisteredCompatibilityMethods_DoNotRequireJavaOverrides'— 2 passed, covering CoreCLR and NativeAOT../dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll --filter 'Name~Build_TrimmableTypeMap_WithCollectionExport_Succeeds|Name~Build_WithTrimmableTypeMap_PublishTrimmed_CompilesLinkedJavaInPlace'— 3 passed, including post-trim Java generation and an incremental rebuild.publish -c Release -r android-arm64 -p:PublishAot=true— passed, producing a signed arm64 APK.javaccompilation of both fixed wrappers — passed.git diff --check— passed.The package's existing dependency-range warnings and NativeAOT analysis warnings remain. No on-device execution was performed.
Pull Request
title and
description
should follow the
commit-messages.mdworkflow documentation, and in particular should include: