Skip to content

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

Description

@tipa

Android framework version

net10.0-android

Affected platform version

Microsoft.Android.Sdk.Windows 36.1.69 (.NET SDK 10.0.301), targeting net10.0-android

Description

Xamarin.Google.Android.Material 1.14.0.5 builds successfully, but a trimmed Release app using Slider.AddOnChangeListener(...) crashes at runtime when R8 is enabled.

The failure is still reproducible with the current .NET for Android workload (Microsoft.Android.Sdk.Windows 36.1.69). I built the attached minimal repro in Release, installed it on a Pixel 7 running Android 17 (API 37), and reproduced the crash immediately at app startup.

This is a follow-up to #1484 and #1493. Version 1.14.0.5 restored the Slider listener APIs/events, but the hand-written binding calls the Java method by its original JNI descriptor. R8 can rename or remove the Material slider listener types/members, so the runtime lookup no longer finds:

Slider.addOnChangeListener(BaseOnChangeListener)

Expected behavior: Slider.AddOnChangeListener(...) works in a trimmed Release/R8 app without application-specific keep rules.

Actual behavior: the Release build succeeds, but the app crashes when AddOnChangeListener is called.

Original report on the closed issue: #1484 (comment)

Steps to Reproduce

  1. Extract and open the attached MaterialSliderR8Repro.zip

  2. Build the Release configuration:

    dotnet build .\MaterialSliderR8Repro.csproj -c Release
  3. Install and launch the generated signed APK.

  4. Observe that the app crashes during MainActivity.OnCreate at:

    slider.AddOnChangeListener(new SliderChangeListener(this));

The relevant project settings are:

<TargetFramework>net10.0-android</TargetFramework>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
  <AndroidLinkTool>r8</AndroidLinkTool>
  <TrimMode>full</TrimMode>
</PropertyGroup>

<PackageReference Include="Xamarin.Google.Android.Material" Version="1.14.0.5" />

Did you find any workaround?

Yes. Adding the following R8/ProGuard rule makes the same Release build launch successfully:

-keep class com.google.android.material.slider.** { *; }

For example:

<ProguardConfiguration Include="proguard.cfg" />

This was verified with the same repro, SDK, and device. The binding package should ideally include the required preservation rule (or otherwise emit an R8-safe binding) so every consuming app does not need to discover and maintain this rule itself.

Relevant log output

FATAL EXCEPTION: main
Process: com.tipa.materialsliderr8repro
java.lang.NoSuchMethodError: no non-static method "Lcom/google/android/material/slider/Slider;.addOnChangeListener(Lcom/google/android/material/slider/BaseOnChangeListener;)V"
    at crc643cb84168043c0d8c.MainActivity.n_onCreate(Native Method)
    at crc643cb84168043c0d8c.MainActivity.onCreate(MainActivity.java:20)
    at android.app.Activity.performCreate(Activity.java:9340)
    at android.app.Activity.performCreate(Activity.java:9318)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1543)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4559)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions