Fix Material Slider ACW implementor build failure (#1484) - #1486
Merged
Conversation
Remove the restricted BaseOnChangeListener/BaseOnSliderTouchListener base interfaces and break the C# implements chain on the typed sub-interfaces to avoid the ACW type-erasure clash. Re-add typed AddOn*/RemoveOn* listener methods via Additions so the public API uses Slider.IOnChangeListener and RangeSlider.IOnChangeListener as recommended by Android. Bump nugetVersion to 1.14.0.4.
There was a problem hiding this comment.
Pull request overview
This PR updates the Material (Xamarin.Google.Android.Material) binding to prevent consumer-side javac failures caused by generated ACW implementors for the Material Slider’s restricted base listener interfaces. It does this by removing the restricted base interfaces from the bound surface, detaching the typed sub-interfaces from the removed base interfaces, and reintroducing listener add/remove APIs via typed Additions methods. It also bumps the NuGet revision to ship the binding-only fix.
Changes:
- Remove
BaseOnChangeListener/BaseOnSliderTouchListenerfrom the binding and detachSlider.*/RangeSlider.*typed listener interfaces from those bases. - Remove the auto-generated
BaseSlideradd/remove listener methods and re-add typedAddOn*/RemoveOn*methods via Additions. - Bump
nugetVersionforcom.google.android.material:materialfrom1.14.0.3to1.14.0.4and update PublicAPI accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| source/com.google.android.material/material/Transforms/Metadata.xml | Removes restricted base listener interfaces and strips/rewires slider listener-related API surface to avoid broken implementor generation. |
| source/com.google.android.material/material/Additions/SliderListenerMethods.cs | Adds typed AddOn*/RemoveOn* listener methods that invoke the correct JNI signatures without relying on the removed base interfaces. |
| source/com.google.android.material/material/PublicAPI/PublicAPI.Unshipped.txt | Updates public API tracking to reflect removed base interfaces and the newly exposed typed listener methods/types. |
| config.json | Bumps nugetVersion for the Material package to ship the binding fix. |
Wrap the JNI invoke in try/finally so GC.KeepAlive runs even when the call throws, preventing premature collection of the listener handle. Addresses PR review feedback.
jonathanpeppers
approved these changes
Jun 29, 2026
jonathanpeppers
pushed a commit
that referenced
this pull request
Jul 2, 2026
…and RangeSlider (#1493) PR #1486 removed the auto-generated addOnChangeListener/addOnSliderTouchListener methods from BaseSlider via remove-node and re-added them as hand-written Additions. However, the binding generator only produces C# events for methods it sees in the API XML — since the methods were removed from the generated API, the Change, StartTrackingTouch, and StopTrackingTouch events were no longer emitted. This caused a regression in 1.14.0.4 where Slider.Change (and touch events) were missing, breaking existing .NET consumers who used the C# event syntax. Fix: add the three events manually to SliderListenerMethods.cs for both Slider and RangeSlider, using EventHelper.AddEventHandler/RemoveEventHandler with the already- generated implementor types (IOnChangeListenerImplementor, IOnSliderTouchListenerImplementor). This is exactly what the generator would have produced had the methods remained in the generated API. The ChangeEventArgs.P0 type changes from Java.Lang.Object (old erased-generic base) to the concrete Slider/RangeSlider — a source-level improvement alongside the fix. Bump nugetVersion 1.14.0.4 -> 1.14.0.5. Fixes #1484
jonathanpeppers
pushed a commit
that referenced
this pull request
Jul 16, 2026
…lease builds (#1502) Instead of removing the base interfaces entirely (PR #1486), keep them intact with their methods so the binding generator produces Implementor ACW classes. These Java ACWs contain 'implements BaseOnChangeListener' which gives R8 a concrete Java reference — preventing it from stripping the types at link time. The implements chain from typed sub-interfaces (Slider.OnChangeListener etc.) to the base interfaces is still broken to prevent ACW erasure clash (#1482). The auto-generated add/remove methods on BaseSlider are still removed and replaced with hand-written typed overloads in Additions. This hybrid approach provides: - Typed API: AddOnChangeListener(Slider.IOnChangeListener) as Android recommends - No erasure clash: implements chain broken between typed and base interfaces - R8 safe: Implementor ACWs reference base types in Java — no ProGuard needed - Events: Change/StartTrackingTouch/StopTrackingTouch hand-written in Additions Fixes #1501
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the Java/ACW compile failure consumers hit when referencing the Xamarin.Google.Android.Material package in a .NET MAUI Android app — even without using the Slider control.
Fixes #1484.
Root cause
BaseOnChangeListener/BaseOnSliderTouchListenerare@RestrictTo(LIBRARY_GROUP)(internal) base interfaces with type-erased generic methods (onValueChange(Object, float, boolean)). The public, recommended types areSlider.OnChangeListener/RangeSlider.OnChangeListener, which extend the base with strongly-typed methods.Because the bound
add/removeListenerpair references the base interface, the generator emits internalImplementortypes decorated with[Register]. Every consuming app generates Android Callable Wrappers for those[Register]types. After PR #1481 stripped the erased base methods (to fix an erasure clash), the implementors and event listeners no longer satisfied the still-present Java abstract methods, so javac failed in every consuming project.Fix
BaseOnChangeListener/BaseOnSliderTouchListenerfrom the binding — this stops the brokenImplementorgeneration at the source.implementschain on the four typed sub-interfaces so they stand alone (no longer extending the removed base) — removes the type-erasure clash entirely.addOnChangeListener/removeOnChangeListener/addOnSliderTouchListener/removeOnSliderTouchListenermethods and re-add typed overloads via Additions with the correct JNI signatures.The public API now exposes the Android-recommended listeners:
Bump nugetVersionto1.14.0.4.Why removal is safe
BaseOnChangeListeneris@RestrictTo(LIBRARY_GROUP)— internal to the Material library, not part of Android's public surface. Dropping it aligns with Google's intent and steers users toSlider.IOnChangeListener/RangeSlider.IOnChangeListener.Validation
Xamarin.Google.Android.Material.dllbuilds with 0 errors.*ImplementorACW types generated for the listeners.Files changed
source/com.google.android.material/material/Transforms/Metadata.xmlsource/com.google.android.material/material/Additions/SliderListenerMethods.cs(new)source/com.google.android.material/material/PublicAPI/PublicAPI.Unshipped.txtconfig.json(nugetVersion 1.14.0.3 → 1.14.0.4)