Skip to content

[Microsoft.Android.Sdk.TrimmableTypeMap] Fix Java overrides - #13242

Merged
simonrozsival merged 1 commit into
mainfrom
simonrozsival-nativeaot-java-overrides
Oct 27, 2026
Merged

simonrozsival merged 1 commit into
mainfrom
simonrozsival-nativeaot-java-overrides

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Fixes #13235.

Publishing an app referencing Xamarin.GooglePlayServices.Ads.Lite 123.4.0 with the trimmable typemap fails with XAJVC0000: the generated MediationBannerListenerImplementor.java applies @Override to zza, 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:

dotnet publish -c Release -r android-arm64 -p:PublishAot=true -p:_AndroidTypeMapImplementation=trimmable

This failed on the @Override annotation at line 78 of the generated wrapper, matching the report. Direct javac compilation of that wrapper reproduced the same error. Publishing with Mono succeeded.

Decompiling the package revealed that Android.Gms.Ads.Mediation.IMediationBannerListener retains a registered default compatibility method, Zza, mapped to Java zza. Inspecting the actual Java interface with javap showed that it declares zzb, not zza. The package's managed implementor also implements Zza, 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 @Override annotation 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 zza and zzb without the invalid annotation.

Validation

  • Before the fix, the new unit regression produced 2 failures and 1 pass, reproducing the connector-dependent annotation bug.
  • 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.
  • Published a standalone reproduction containing Ads.Lite and a user listener with the fixed local SDK using publish -c Release -r android-arm64 -p:PublishAot=true — passed, producing a signed arm64 APK.
  • Direct javac compilation 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.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

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]>
Copilot AI balanced review requested due to automatic review settings October 22, 2026 20:33

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.

🟢 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

@simonrozsival
simonrozsival enabled auto-merge (squash) October 27, 2026 08:17
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 27, 2026
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13242

@github-actions github-actions Bot 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.

Code assessment: no blocking findings. 0 ❌ errors, 0 ⚠️ warnings, 1 💡 non-blocking inline testing suggestion.

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 ();

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.

🤖 💡 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}

@simonrozsival
simonrozsival merged commit 234f144 into main Oct 27, 2026
42 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-nativeaot-java-overrides branch October 27, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NativeAOT] XAJVC0000 with Xamarin.GooglePlayServices.Ads.Lite

3 participants