Fix R8 stripping BaseOnChangeListener/BaseOnSliderTouchListener in Release builds#1502
Merged
Merged
Conversation
…lease builds 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
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the Material Slider binding to prevent R8 from stripping BaseOnChangeListener / BaseOnSliderTouchListener in Release builds, addressing runtime NoSuchMethodError crashes when the binding invokes listener APIs via hand-written JNI.
Changes:
- Restores the base listener interfaces in the binding while removing the
implementsrelationship from typed sub-interfaces to avoid the ACW erasure clash. - Removes the auto-generated
BaseSlideradd/remove listener methods (continuing the “re-add typed methods via Additions” approach). - Bumps
Xamarin.Google.Android.MaterialnugetVersionto1.14.0.6and updatesPublicAPI.Unshipped.txtto reflect the restored public surface.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| source/com.google.android.material/material/Transforms/Metadata.xml | Restores base slider listener interfaces, breaks typed-sub-interface inheritance from base interfaces, and removes auto-generated BaseSlider add/remove methods. |
| source/com.google.android.material/material/PublicAPI/PublicAPI.Unshipped.txt | Adds back public API entries corresponding to the restored base interfaces/event args. |
| config.json | Bumps Material NuGet revision to 1.14.0.6. |
jonathanpeppers
approved these changes
Jul 16, 2026
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.
Problem
In Release builds with R8 enabled, apps using Material Slider crash with
NoSuchMethodErrorbecause R8 stripsBaseOnChangeListenerandBaseOnSliderTouchListenertypes — no Java code references them after PR #1486 removed the interfaces entirely.Fixes #1501
Fix
Instead of removing
IBaseOnChangeListenerandIBaseOnSliderTouchListenerentirely, keep them intact with their methods. This causes the binding generator to produce Implementor ACW classes containingimplements BaseOnChangeListenerin Java — giving R8 a traceable reference that prevents stripping.To avoid the erasure clash (#1482), the
implementschain from typed sub-interfaces (Slider.OnChangeListener,RangeSlider.OnChangeListener, etc.) to the base interfaces is broken viaremove-nodein Metadata.xml.The auto-generated
addOnChangeListener/removeOnChangeListenermethods onBaseSliderare removed and replaced with hand-written typed overloads in Additions that acceptSlider.IOnChangeListener(the Android-recommended API) while using the correct erased JNI signature internally.Changes
Metadata.xml: Reverted removal of base interfaces; addedremove-nodefor implements chain and auto-generated add/remove methods on BaseSliderconfig.json: Bumped nugetVersion to 1.14.0.6PublicAPI.Unshipped.txt: Regenerated to reflect restored base interfaces