Skip to content

Fix R8 stripping BaseOnChangeListener/BaseOnSliderTouchListener in Release builds#1502

Merged
jonathanpeppers merged 1 commit into
mainfrom
fix/slider-simple-implements-only
Jul 16, 2026
Merged

Fix R8 stripping BaseOnChangeListener/BaseOnSliderTouchListener in Release builds#1502
jonathanpeppers merged 1 commit into
mainfrom
fix/slider-simple-implements-only

Conversation

@sheiksyedm

@sheiksyedm sheiksyedm commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Problem

In Release builds with R8 enabled, apps using Material Slider crash with NoSuchMethodError because R8 strips BaseOnChangeListener and BaseOnSliderTouchListener types — no Java code references them after PR #1486 removed the interfaces entirely.

Fixes #1501

Fix

Instead of removing IBaseOnChangeListener and IBaseOnSliderTouchListener entirely, keep them intact with their methods. This causes the binding generator to produce Implementor ACW classes containing implements BaseOnChangeListener in Java — giving R8 a traceable reference that prevents stripping.

To avoid the erasure clash (#1482), the implements chain from typed sub-interfaces (Slider.OnChangeListener, RangeSlider.OnChangeListener, etc.) to the base interfaces is broken via remove-node in Metadata.xml.

The auto-generated addOnChangeListener/removeOnChangeListener methods on BaseSlider are removed and replaced with hand-written typed overloads in Additions that accept Slider.IOnChangeListener (the Android-recommended API) while using the correct erased JNI signature internally.

Changes

  • Metadata.xml: Reverted removal of base interfaces; added remove-node for implements chain and auto-generated add/remove methods on BaseSlider
  • config.json: Bumped nugetVersion to 1.14.0.6
  • PublicAPI.Unshipped.txt: Regenerated to reflect restored base interfaces

…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
Copilot AI review requested due to automatic review settings July 16, 2026 12:05
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 implements relationship from typed sub-interfaces to avoid the ACW erasure clash.
  • Removes the auto-generated BaseSlider add/remove listener methods (continuing the “re-add typed methods via Additions” approach).
  • Bumps Xamarin.Google.Android.Material nugetVersion to 1.14.0.6 and updates PublicAPI.Unshipped.txt to 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.

Comment thread source/com.google.android.material/material/Transforms/Metadata.xml
Comment thread source/com.google.android.material/material/Transforms/Metadata.xml
@jonathanpeppers
jonathanpeppers merged commit 75a51fd into main Jul 16, 2026
3 checks passed
@jonathanpeppers
jonathanpeppers deleted the fix/slider-simple-implements-only branch July 16, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xamarin.Google.Android.Material 1.14.0.5: Slider.AddOnChangeListener crashes in Release/R8 with NoSuchMethodError

3 participants