dotnet/android-libraries

Xamarin.AndroidX.Fragment FragmentManager Java.Lang.AbstractMethodError crash

Opened this issue · 2 comments

Android framework version

net8.0-android

Affected platform version

VS for Mac 17.6.14, .NET 8.0.404

Description

I am getting this crash after adding IOnBackStackChangedListener to my activity:

Java.Lang.AbstractMethodError: abstract method "void androidx.fragment.app.FragmentManager$OnBackStackChangedListener.onBackStackChangeStarted(androidx.fragment.app.Fragment, boolean)"
  at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:20830
  at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:75
  at AndroidX.Fragment.App.FragmentManager.IOnBackStackChangedListener.OnBackStackChangeStarted(Fragment fragment, Boolean pop) in D:\a\_work\1\s\generated\androidx.fragment.fragment\obj\Release\net8.0-android\generated\src\AndroidX.Fragment.App.FragmentManager.cs:986
  at AndroidX.Fragment.App.FragmentManager.IOnBackStackChangedListener.n_OnBackStackChangeStarted_Landroidx_fragment_app_Fragment_Z(IntPtr jnienv, IntPtr native__this, IntPtr native_fragment, Boolean pop) in D:\a\_work\1\s\generated\androidx.fragment.fragment\obj\Release\net8.0-android\generated\src\AndroidX.Fragment.App.FragmentManager.cs:973
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLZ_V(_JniMarshal_PPLZ_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, Boolean p1) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:187
  at java.lang.AbstractMethodError: abstract method "void androidx.fragment.app.FragmentManager$OnBackStackChangedListener.onBackStackChangeStarted(androidx.fragment.app.Fragment, boolean)
  at at onBackStackChangeStarted(Native Method)
  at at onBackStackChangeStarted(MainView.java:211)
  at at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2131)
  at at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2058)
  at at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2001)
  at at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:702)
  at at android.os.Handler.handleCallback(Handler.java:938)
  at at android.os.Handler.dispatchMessage(Handler.java:99)
  at at android.os.Looper.loopOnce(Looper.java:226)
  at at android.os.Looper.loop(Looper.java:313)
  at at android.app.ActivityThread.main(ActivityThread.java:8751)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Looks like it expects me to override method onBackStackChangeStarted(), but I can't do it.

Steps to Reproduce

  1. On activity add IOnBackStackChanged interface inheritance
  2. Add this activity as listener to SupportFragmentManager - SupportFragmentManager.AddOnBackStackChangedListener(this);
  3. Do actions to invoke onBackStackChangeStarted method.

Did you find any workaround?

No response

Relevant log output

I can confirm this issue. It makes it hard or impossible to implement AndroidX based preference screens properly.

@RoNko72 @PhilippC

Thanks for the feedback. I will look into the issue.