xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

Java.lang.RuntimeException in NavigationPageRenderer.Dispose #7874

Open mrbelk opened 5 years ago

mrbelk commented 5 years ago

Description

I am experiencing a RuntimeException or ClassCastException in the NavigationPageRenderer.Dispose method during the FragmentManager "teardown" with the following stack trace:

Java.Interop
JniEnvironment+InstanceMethods.CallBooleanMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)
Java.Interop
JniPeerMembers+JniInstanceMethods.InvokeAbstractBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
Android.Support.V4.App
FragmentManagerInvoker.ExecutePendingTransactions ()
Xamarin.Forms.Platform.Android
FragmentManagerExtensions.ExecutePendingTransactionsEx (Android.Support.V4.App.FragmentManager fragmentTransaction) D:\a\1\s\Xamarin.Forms.Platform.Android\Extensions\FragmentManagerExtensions.cs:42
Xamarin.Forms.Platform.Android.AppCompat
NavigationPageRenderer.Dispose (System.Boolean disposing) D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:199
goRoamPOD.Droid.Renderers
GoRoamNavigationPageRenderer.Dispose (System.Boolean disposing) /Users/matthew/Projects/goRoamPOD/goRoamPOD.Android/Renderers/NavigationPageRenderer.cs:22
java.lang.ClassCastException: com.google.maps.api.android.lib6.impl.ao cannot be cast to android.view.ViewGroup
android.support.v4.app.FragmentTransition.configureTransitionsOrdered FragmentTransition.java:312
android.support.v4.app.FragmentTransition.startTransitions FragmentTransition.java:136
android.support.v4.app.FragmentManagerImpl.executeOpsTogether FragmentManager.java:2408
android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute FragmentManager.java:2366
android.support.v4.app.FragmentManagerImpl.execPendingActions FragmentManager.java:2273
android.support.v4.app.FragmentManagerImpl.executePendingTransactions FragmentManager.java:814
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run RunnableImplementor.java:30
android.os.Handler.handleCallback Handler.java:739
android.os.Handler.dispatchMessage Handler.java:95
android.os.Looper.loop Looper.java:148
android.app.ActivityThread.main ActivityThread.java:5417
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run ZygoteInit.java:726
com.android.internal.os.ZygoteInit.main ZygoteInit.java:616

My app uses Prism with Unity (v7.1.0.431) and this particular error happens when I navigate to a new "absolute" URL using the navigationService.NavigateAsync("/path/to/page"). The stack trace would indicate something in google maps, but in some cases the navigation stack doesn't contain any maps, but it would have included calls to get location using James Montemagno's Xamarin.Plugin.Geolocator plugin. I implemented a new NavigationPageRenderer that inherits from the base class so I could trap this particular exception and log it to AppCenter.

I assume that it's not safe to simply swallow this exception and move on.

I was getting sporadic crash reports from this when the app was based on Xamarin.Forms 4.1, but after deploying an update based on XF 4.2, the incidents reported in AppCenter shot up dramatically.

The " com.google.maps.api.android.lib6.impl.ao" changes based on the Android platform to "com.google.maps.api.android.lib6.impl.ap" or "com.google.maps.api.android.lib6.impl.an"

I am attaching a representative crash log from AppCenter: report-2518320998650179999-974b406a-e001-430b-bcef-3784c4b55064.txt

Expected Behavior

The navigation page should dispose without error

Actual Behavior

an uncaught Java.lang.RuntimeException or java.lang.ClassCastException is thrown in when Xamarin.Forms.Platform.Android.FragmentManagerExtensions.ExecutePendingTransactionsEx us called during the execution of the Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.Dispose method.

Basic Information

mrbelk commented 5 years ago

I think this is a Xamarin.Android problem more-so than anything with the Nuget packages being used. I just downgraded XF (including the maps package) to the latest 4.1 version from the latest 4.2 version; downgraded the Xamarin.GooglePlayServices packages to 60.1142.1 from 71.1610.0 and this still happens. Is there a way to target an "older" Xamarin.Android version from visual studio? I just now updated to Xamarin.Android 10.0.3.0 and VS 8.3.2 (build 32).

I'm going to change the target Xamarin.Android version in AppCenter and kick off a build to see if that maybe solves this.

mrbelk commented 5 years ago

Update: It doesn't appear to be an issue with the Xamarin.Android version, using the latest versions of XF, Xamarin.Android., and Xamarin.GooglePlayServices. packages. I am going to downgrade the Xamarin.Android.* from 28.0.0.3 to 28.0.0.1 and see what happens

jfversluis commented 5 years ago

Hi @mrbelk thanks for the thorough investigation! Have you been able to dig up any more to pinpoint the exact origin of this?

mrbelk commented 5 years ago

Unfortunately not. I tried several different combinations of xamarin.forms., xamarin.android., xamarin.googleplayservices.* with no apparent change. I tried backing off the Xamarin.Android/Mono version in the app center build config and that didn't help either.

What did help, however, was completely uninstalling and reinstalling the app. We don't have this in the Google Play Store because it's a private B2B app that can target a SaaS or on-premise backend and is deployed via an MDM solution like MaaS or SOTI.

jfversluis commented 5 years ago

OK, so, that almost sounds like there might have been some old version of a library on there that caused this? A reinstall fixes it consistently then?

mrbelk commented 5 years ago

It does on the devices where we've tried it (internal test devices). The app is on devices in the field at our customers with their drivers in all time zones and using it at all times of the day, so it's challenging to coordinate getting one before or after the route is over and the device is back at the depot or otherwise not in use.

PureWeen commented 4 years ago

@mrbelk hmm this is a tricky one

We have a previous bugzilla issue with this but I don't see a specific resolution https://xamarin.github.io/bugzilla-archives/59/59127/bug.html

lestersconyers commented 4 years ago

+1 I'm having the same issue with tabbed page. When performing absolute navigation, I get the error above. Logcat output below

logcat.txt

samhouts commented 4 years ago

@lestersconyers Can you please attach a small project that demonstrates this issue? Thanks!

lestersconyers commented 4 years ago

@samhouts Sorry for the delay. I've tried several attempts at this from a blank project and have not been able to reproduce. However, my production app crashes every time consistently. Unfortunately I can't share that source at the time.

lestersconyers commented 4 years ago

@mrbelk Does your app continue to run after swallowing the error? Has the problem gone away since uninstall/reinstalling on devices?

mrbelk commented 4 years ago

@lestersconyers Yes, it does continue to run after swallowing the error. I cannot consistently reproduce the problem in a lab environment, though

@PureWeen Is there a way to get a logcat dump programmatically without constantly streaming it?

banditoth commented 4 years ago

Have a similar problem with maybe the map. XF: 4.6.0.800 XFM: 4.6.0.800

Java.Lang.ClassCastException: com.google.maps.api.android.lib6.impl.an cannot be cast to android.view.ViewGroup
  at Java.Interop.JniEnvironment+InstanceMethods.CallBooleanMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <26521a5118b44c858c385715922b9d5d>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00014] in <26521a5118b44c858c385715922b9d5d>:0 
  at AndroidX.Fragment.App.FragmentManagerInvoker.ExecutePendingTransactions () [0x0000a] in <3337aeffcf9142d295ca64c7fd0511af>:0 
  at Xamarin.Forms.Platform.Android.FragmentManagerExtensions.ExecutePendingTransactionsEx (AndroidX.Fragment.App.FragmentManager fragmentManager) [0x00000] in <63e7c9910ab446ac9b78b1ac3ac3e5bb>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailContainer.Dispose (System.Boolean disposing) [0x00054] in <63e7c9910ab446ac9b78b1ac3ac3e5bb>:0 
  at Java.Lang.Object.Dispose () [0x00000] in <d3b924763d4a465c85b26f6e8edc8a53>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer.Dispose (System.Boolean disposing) [0x000fd] in <63e7c9910ab446ac9b78b1ac3ac3e5bb>:0 
  at Java.Lang.Object.Dispose () [0x00000] in <d3b924763d4a465c85b26f6e8edc8a53>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.Platform+<>c__DisplayClass45_0.<Cleanup>g__DoCleanup|0 () [0x00064] in <63e7c9910ab446ac9b78b1ac3ac3e5bb>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <d3b924763d4a465c85b26f6e8edc8a53>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <d3b924763d4a465c85b26f6e8edc8a53>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.78(intptr,intptr)
  --- End of managed Java.Lang.ClassCastException stack trace ---
java.lang.ClassCastException: com.google.maps.api.android.lib6.impl.an cannot be cast to android.view.ViewGroup
    at androidx.fragment.app.FragmentTransition.configureTransitionsOrdered(FragmentTransition.java:314)
    at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:138)
    at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1866)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
    at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
    at androidx.fragment.app.FragmentManagerImpl.executePendingTransactions(FragmentManagerImpl.java:183)
    at mono.java.lang.RunnableImplementor.n_run(Native Method)
    at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7948)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)