Commit 4c9ad50
Fixes #1491.
## Problem
`AdLoadCallback<AdT>` declares `public void onAdLoaded(AdT ad)`, which erases to `onAdLoaded(Object)` in bytecode. The binding therefore only exposes `virtual OnAdLoaded(Java.Lang.Object p0)` on every concrete subclass:
- `AdManagerInterstitialAdLoadCallback`
- `InterstitialAdLoadCallback`
- `RewardedAdLoadCallback`
- `RewardedInterstitialAdLoadCallback`
- `AppOpenAd.AppOpenAdLoadCallback`
When a user overrides that in C#, the generated ACW Java stub emits `public void onAdLoaded(java.lang.Object p0)`, and javac rejects it:
```
error: name clash: onAdLoaded(Object) in MyCallback and
onAdLoaded(AdManagerInterstitialAd) in AdLoadCallback have the same
erasure, yet neither overrides the other
```
After generic substitution the parent's real method is the specialized one, so the erased override doesn't satisfy javac.
## Fix
For each concrete `*AdLoadCallback` subclass, add a specialized `onAdLoaded(SpecificAd)` method via `<add-node>` in the binding's `Transforms/Metadata.xml`. The binding now surfaces a properly-typed `virtual OnAdLoaded(SpecificAd)` with a specialized JNI registration, e.g.:
```csharp
[Register("onAdLoaded", "(Lcom/google/android/gms/ads/admanager/AdManagerInterstitialAd;)V",
"GetOnAdLoaded_Lcom_google_android_gms_ads_admanager_AdManagerInterstitialAd_Handler")]
public virtual unsafe void OnAdLoaded(AdManagerInterstitialAd p0) { ... }
```
Users override the specialized overload, and the resulting ACW stub emits the specialized Java signature that correctly overrides the parent — matching how Google's docs show the callback being subclassed in Java.
The same fix is applied in **both** bindings that ship these types:
- `play-services-ads-lite` — `Android.Gms.Ads.*` namespace (used by `Xamarin.GooglePlayServices.Ads.Lite` direct consumers).
- `play-services-ads-api` — `Google.Android.Gms.Ads.*` namespace (pulled in transitively by `Xamarin.GooglePlayServices.Ads`, which is what the issue reporter uses).
Both `.aar`s independently contain the `*AdLoadCallback.class` files and each produces its own set of .NET types, so the metadata must be added in both places.
## Version bumps
- `Xamarin.GooglePlayServices.Ads.Lite`: `124.0.0.6` → `124.0.0.7`
- `Xamarin.GooglePlayServices.Ads.Api`: `125.4.0.1` → `125.4.0.2`
- `Xamarin.GooglePlayServices.Ads`: `125.4.0.1` → `125.4.0.2`
## User-facing migration
Users hitting `javac.exe error JAVAC0000` from #1491 should change:
```csharp
public override void OnAdLoaded(Java.Lang.Object p0) { ... }
```
to the specialized overload, e.g.:
```csharp
public override void OnAdLoaded(AdManagerInterstitialAd p0) { ... }
```
## Verification
- `dotnet cake --target=metadata-verify` passes.
- Built both `com.google.android.gms.play-services-ads-lite` and `com.google.android.gms.play-services-ads-api` locally (against a project-referenced `Ads.Base` since the published `Ads.Base 124.0.0.1` NuGet does not yet target `net10.0-android36`) — build succeeded, 0 warnings, 0 errors.
- Verified generated `*AdLoadCallback.cs` in each project's `obj/` contains the specialized `virtual void OnAdLoaded(SpecificAd p0)` with the expected `[Register("onAdLoaded", "(Lcom/.../SpecificAd;)V", ...)]`.
- All 5 specialized overloads picked up in `PublicAPI.Unshipped.txt` for both packages by the analyzer.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent fe9978d commit 4c9ad50
5 files changed
Lines changed: 139 additions & 3 deletions
File tree
- source/com.google.android.gms
- play-services-ads-api
- PublicAPI
- Transforms
- play-services-ads-lite
- PublicAPI
- Transforms
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2730 | 2730 | | |
2731 | 2731 | | |
2732 | 2732 | | |
2733 | | - | |
| 2733 | + | |
2734 | 2734 | | |
2735 | 2735 | | |
2736 | 2736 | | |
| |||
2740 | 2740 | | |
2741 | 2741 | | |
2742 | 2742 | | |
2743 | | - | |
| 2743 | + | |
2744 | 2744 | | |
2745 | 2745 | | |
2746 | 2746 | | |
| |||
2764 | 2764 | | |
2765 | 2765 | | |
2766 | 2766 | | |
2767 | | - | |
| 2767 | + | |
2768 | 2768 | | |
2769 | 2769 | | |
2770 | 2770 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
230 | 241 | | |
231 | 242 | | |
232 | 243 | | |
| |||
1375 | 1386 | | |
1376 | 1387 | | |
1377 | 1388 | | |
| 1389 | + | |
1378 | 1390 | | |
1379 | 1391 | | |
1380 | 1392 | | |
| |||
1387 | 1399 | | |
1388 | 1400 | | |
1389 | 1401 | | |
| 1402 | + | |
1390 | 1403 | | |
1391 | 1404 | | |
1392 | 1405 | | |
| |||
1412 | 1425 | | |
1413 | 1426 | | |
1414 | 1427 | | |
| 1428 | + | |
1415 | 1429 | | |
1416 | 1430 | | |
1417 | 1431 | | |
| |||
1503 | 1517 | | |
1504 | 1518 | | |
1505 | 1519 | | |
| 1520 | + | |
1506 | 1521 | | |
1507 | 1522 | | |
| 1523 | + | |
1508 | 1524 | | |
1509 | 1525 | | |
1510 | 1526 | | |
| |||
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
128 | 187 | | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1336 | 1336 | | |
1337 | 1337 | | |
1338 | 1338 | | |
| 1339 | + | |
1339 | 1340 | | |
1340 | 1341 | | |
1341 | 1342 | | |
| |||
1346 | 1347 | | |
1347 | 1348 | | |
1348 | 1349 | | |
| 1350 | + | |
1349 | 1351 | | |
1350 | 1352 | | |
1351 | 1353 | | |
| |||
1369 | 1371 | | |
1370 | 1372 | | |
1371 | 1373 | | |
| 1374 | + | |
1372 | 1375 | | |
1373 | 1376 | | |
1374 | 1377 | | |
| |||
1454 | 1457 | | |
1455 | 1458 | | |
1456 | 1459 | | |
| 1460 | + | |
1457 | 1461 | | |
1458 | 1462 | | |
| 1463 | + | |
1459 | 1464 | | |
1460 | 1465 | | |
1461 | 1466 | | |
| |||
Lines changed: 56 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
130 | 186 | | |
131 | 187 | | |
132 | 188 | | |
| |||
0 commit comments