xamarin / Xamarin.Forms

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

Xamarin.AndroidX.Fragment needs to be adjusted or bumped.... #14193

Open WilliamWatterson86 opened 3 years ago

WilliamWatterson86 commented 3 years ago

Description

Email.ComposeAsync crashes app with Java.Lang.IllegalStateException: FragmentContainer does not have a view

In my code I have a button that will open the email client with a preselected "To" address.

This is the code I am using. var message = new EmailMessage { To = recipients, }; await Email.ComposeAsync(message);

The call to Email.ComposeAsync looks like it working fine, I get the dialog to choose which email app I want to use, then when I select one, my app in the background crashes with this error. This does not happen with other Xamarin Essentials things like "Share" options when email is selected.

Steps to Reproduce

  1. Call await Email.ComposeAsync(message);
  2. Select email app you want to use
  3. App crashes

Expected Behavior

App should remain where it was until the user has finished sending their email

Actual Behavior

App crashes when email app is selected

Basic Information

Screenshots

image

JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue args) JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue parameters) Activity.OnStart () FormsAppCompatActivity.OnStart () D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:417 Activity.n_OnStart (System.IntPtr jnienv, System.IntPtr native__this) (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.23(intptr,intptr) java.lang.IllegalStateException: Fragment FragmentContainer{2ab20f} (753ad94b-2740-4b04-8c2b-8b68181c275e) id=0x7} does not have a view androidx.fragment.app.Fragment$4.onFindViewById Fragment.java:2888 androidx.fragment.app.FragmentStateManager.createView FragmentStateManager.java:501 androidx.fragment.app.FragmentStateManager.moveToExpectedState FragmentStateManager.java:282 androidx.fragment.app.FragmentStore.moveToExpectedState FragmentStore.java:112 androidx.fragment.app.FragmentManager.moveToState FragmentManager.java:1636 androidx.fragment.app.FragmentManager.dispatchStateChange FragmentManager.java:3112 androidx.fragment.app.FragmentManager.dispatchActivityCreated FragmentManager.java:3056 androidx.fragment.app.Fragment.performActivityCreated Fragment.java:2989 androidx.fragment.app.FragmentStateManager.activityCreated FragmentStateManager.java:577 androidx.fragment.app.FragmentStateManager.moveToExpectedState FragmentStateManager.java:285 androidx.fragment.app.FragmentStore.moveToExpectedState FragmentStore.java:112 androidx.fragment.app.FragmentManager.moveToState FragmentManager.java:1636 androidx.fragment.app.FragmentManager.dispatchStateChange FragmentManager.java:3112 androidx.fragment.app.FragmentManager.dispatchActivityCreated FragmentManager.java:3056 androidx.fragment.app.FragmentController.dispatchActivityCreated FragmentController.java:251 androidx.fragment.app.FragmentActivity.onStart FragmentActivity.java:473 androidx.appcompat.app.AppCompatActivity.onStart AppCompatActivity.java:210 crc643f46942d9dd1fff9.FormsAppCompatActivity.n_onStart(Native Method) crc643f46942d9dd1fff9.FormsAppCompatActivity.onStart FormsAppCompatActivity.java:128 android.app.Instrumentation.callActivityOnStart Instrumentation.java:1433 android.app.Activity.performStart Activity.java:7980 android.app.ActivityThread.handleStartActivity ActivityThread.java:3578 android.app.servertransaction.TransactionExecutor.performLifecycleSequence TransactionExecutor.java:221 android.app.servertransaction.TransactionExecutor.cycleToPath TransactionExecutor.java:201 android.app.servertransaction.TransactionExecutor.executeLifecycleState TransactionExecutor.java:173 android.app.servertransaction.TransactionExecutor.execute TransactionExecutor.java:97 android.app.ActivityThread$H.handleMessage ActivityThread.java:2220 android.os.Handler.dispatchMessage Handler.java:107 android.os.Looper.loop Looper.java:237 android.app.ActivityThread.main ActivityThread.java:8016 java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:493 com.android.internal.os.ZygoteInit.main ZygoteInit.java:1076

Reproduction Link

WilliamWatterson86 commented 3 years ago

Update - specifically installing Xamarin.AndroidX.Fragment v1.2.5.4 seems to stop the crash.

matteopiccioni commented 3 years ago

Same problem for me

pro777s commented 3 years ago

I have a similar error. My Xamarin.Forms has version 5.0.0.2012 and Xamarin.AndroidX.Fragment v1.3.1.

pboisso commented 3 years ago

Same here.

Alex-Dobrynin commented 3 years ago

I have the same problem! Have the latest Xamarin.Forms 5.0.0.2012 and Xamarin.AndroidX.Fragment 1.3.2 installed @jamesmontemagno why is it closed? too many people have this issue

jamesmontemagno commented 3 years ago

So, we don't take a dependency on this nuget, Xamarin.Forms does via https://www.nuget.org/packages/Xamarin.AndroidX.Legacy.Support.V4/ so i will transfer the issue there. It looks like that will need to be bumped there.

agusibrahim commented 3 years ago

same here, i look report from appcenter and google play store, many my customer affected. help

androidx.fragment.app.Fragment$4.onFindViewById Java.Lang.IllegalStateException: Fragment FragmentContainer{21084c4} (e687202c-12b0-4c6d-a6b9-f87f17028f31) id=0x1} does not have a view

gogolon commented 3 years ago

I probably have the same problem (all nugets are up to date):

java.lang.IllegalStateException: 
  at androidx.fragment.app.Fragment$4.onFindViewById (Fragment.java:2888)
  at androidx.fragment.app.FragmentStateManager.createView (FragmentStateManager.java:501)
  at androidx.fragment.app.FragmentStateManager.moveToExpectedState (FragmentStateManager.java:282)
  at androidx.fragment.app.FragmentStore.moveToExpectedState (FragmentStore.java:112)
  at androidx.fragment.app.FragmentManager.moveToState (FragmentManager.java:1636)
  at androidx.fragment.app.FragmentManager.dispatchStateChange (FragmentManager.java:3112)
  at androidx.fragment.app.FragmentManager.dispatchActivityCreated (FragmentManager.java:3056)
  at androidx.fragment.app.Fragment.performActivityCreated (Fragment.java:2989)
  at androidx.fragment.app.FragmentStateManager.activityCreated (FragmentStateManager.java:577)
  at androidx.fragment.app.FragmentStateManager.moveToExpectedState (FragmentStateManager.java:285)
  at androidx.fragment.app.FragmentStore.moveToExpectedState (FragmentStore.java:112)
  at androidx.fragment.app.FragmentManager.moveToState (FragmentManager.java:1636)
  at androidx.fragment.app.FragmentManager.dispatchStateChange (FragmentManager.java:3112)
  at androidx.fragment.app.FragmentManager.dispatchActivityCreated (FragmentManager.java:3056)
  at androidx.fragment.app.FragmentController.dispatchActivityCreated (FragmentController.java:251)
  at androidx.fragment.app.FragmentActivity.onStart (FragmentActivity.java:473)
  at androidx.appcompat.app.AppCompatActivity.onStart (AppCompatActivity.java:210)
  at crc643f46942d9dd1fff9.FormsAppCompatActivity.n_onStart (Native Method)
  at crc643f46942d9dd1fff9.FormsAppCompatActivity.onStart (FormsAppCompatActivity.java:128)
  at android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1435)
  at android.app.Activity.performStart (Activity.java:8222)
  at android.app.ActivityThread.handleStartActivity (ActivityThread.java:3818)
  at android.app.servertransaction.TransactionExecutor.performLifecycleSequence (TransactionExecutor.java:221)
  at android.app.servertransaction.TransactionExecutor.cycleToPath (TransactionExecutor.java:201)
  at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:173)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:97)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2307)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:246)
  at android.app.ActivityThread.main (ActivityThread.java:8506)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)
jamesmontemagno commented 3 years ago

Workaround is to just manually install the latest 'Xamarin.AndroidX.Fragment' nuget package.

gogolon commented 3 years ago

@jamesmontemagno Even after manually installing the mentioned package, the app keeps crashing on Android 11. What can I do?

jamesmontemagno commented 3 years ago

Did you install Xamarin.AndroidX.Fragment v1.2.5.4 ? or a newer one? looks like some investigation may need to be done.

gogolon commented 3 years ago

I've installed the latest version, 1.3.2. Should I roll back to v1.2.5.4? I don't even know what action in the app precedes the crashes, as I'm unable to reproduce them on emulators. I only get reports from the Play console, all the same as the one I posted above.

DevEddy commented 3 years ago

Same here, any new infos on this?

I cannot reproduce, but I can see it on Google ARNs image

jamesmontemagno commented 3 years ago

@gogolon earlier someone said rolling back to 1.2.5.4 fixed their issue.

nielsbrg commented 3 years ago

This error occurred for me whenever the app went from the background back into the foreground. OnResume was not even called, it just instantly crashed with this error. Rolled back to 1.2.5.4 only to get this error. I then installed Xamarin.AndroidX.Activity 1.2.2 and Fragment 1.2.5.4 to resolve everything.

DevEddy commented 3 years ago

I can confirm that the downgrade fixes the issue, thanks @nielsbrg I had to downgrade other dependencies as well. Hope this will get fixed soon.

xleon commented 3 years ago

Same thing here. Can't reproduce myself (debug or release version), but Google console is full of it.

I will try your workaround on my next release.

image

xleon commented 3 years ago

Confirmed that the workaround above fixed all of my crashes

image

As a side note: it happened to (random?) devices above Android 9+

alexanderdibenedetto commented 3 years ago

Can confirm the issue still persists without downgrading to 1.2.5.4. Is there an estimate for fixing this?

suggyd commented 3 years ago

Xamarin.AndroidX.Fragment 1.2.5.4 seems to fix it, but that is a whole 6 versions behind current. Is there any news on a fixed version?

AntRemo commented 3 years ago

Tested with 1.4.0 and still get same error...

I am able to reproduce with:

  1. Launch App
  2. Tap Home
  3. Run adb shell "am kill <PackageName>"
  4. Resume app... KABOOM!

1.2.5.4 has no error.

FYI @DevEddy @xleon @jamesmontemagno

EmilAlipiev commented 3 years ago

This was i think all the time issue with Xamarin even on Xamarin.Android reported long time a go on SO. https://stackoverflow.com/questions/39068772/xamarin-forms-android-java-lang-illegalstateexception-fragment-does-not-have-a

It is crucial issue indeed. we need to find a solution on this.

EmilAlipiev commented 3 years ago

d with 1.4.0 and still get same error...

I am able to reproduce with:

I am seeing the error in my appcenter logs but i am not able reproduce with the way you described even without having Xamarin.AndroidX.Fragment installed. I am testing on Android 11 device

EmilAlipiev commented 3 years ago

any idea how can reproduce and solve this? this is really getting annoying 100s of crashes

pro777s commented 3 years ago

any idea how can reproduce and solve this? this is really getting annoying 100s of crashes

Did downgrading the library Xamarin.Android.Fragment to version 1.2.5.4 help you?

suggyd commented 3 years ago

@pro777s - yes it did for me

EmilAlipiev commented 3 years ago

yes but is that a good solution to go so many versions older? because when you try to downgrade Fragment package, it automatically downgrades all related packages. So you need to basically use all AndroidX packages from 1.2.5.4. I don't find this is a good solution.

pro777s commented 3 years ago

@EmilAlipiev, I agree with you. I don't understand why there is no reaction from the Xamarin developers.

agusibrahim commented 3 years ago

there is no Xamarin.Android.Fragment installed on my android project, should i new install Xamarin.Android.Fragment 1.2.5.4 can solved this issue?

EmilAlipiev commented 3 years ago

Normally you don't need it. I also don't have it but for workaround it's claimed that you need to install the older version which makes no sense. It's pretty old and I am afraid that it can cause other issues

masiton commented 3 years ago

Can confirm, installing Xamarin.Android.Fragment 1.2.5.4 fixed a crash in our XF app when changing between dark/light mode. Same exception was occurring and also newer versions of this dependency didn't work. Specifically version 1.2.5.4 must be used to avoid crashing.

agusibrahim commented 3 years ago

Can confirm, installing Xamarin.Android.Fragment 1.2.5.4 fixed a crash in our XF app when changing between dark/light mode. Same exception was occurring and also newer versions of this dependency didn't work. Specifically version 1.2.5.4 must be used to avoid crashing.

which version of xamarin.forms you're used?

masiton commented 3 years ago

which version of xamarin.forms you're used?

5.0.0.2012.

Codelisk commented 2 years ago

Any updates on this one? i would like to update :)

Jakar510 commented 2 years ago

@Codelisk

It's already has released. See https://github.com/xamarin/Xamarin.Forms/releases/tag/release-5.0.0-sr4

DevEddy commented 2 years ago

Can anyone confirm that the SR fixes the issues?

Jakar510 commented 2 years ago

@DevEddy

I've been using it for a couple of weeks and have not had any issues.

IeuanWalker commented 2 years ago

Also noticed this issue in google develop console. It's one of the main crashes in out app - image

Only an issue with the latest version of our app, you can see the crashes come flooding in after the latest release - image

There where a lot of change in that release (lots of accessibility work), but most notably was -

DevEddy commented 2 years ago

@IeuanWalker have you tried Xamarin.Forms 5.0.0.2083? This seems to be the SR4 where the issue should be fixed.

IeuanWalker commented 2 years ago

@DevEddy no not yet.

I'll update it for the next release.

It's hard to test any changes as it seams to happen randomly throughout the app

DevEddy commented 2 years ago

@AntRemo was able to reproduce this issue, maybe you can try it on your side.

Tested with 1.4.0 and still get same error...

I am able to reproduce with:

  1. Launch App
  2. Tap Home
  3. Run adb shell "am kill <PackageName>"
  4. Resume app... KABOOM!

1.2.5.4 has no error.

FYI @DevEddy @xleon @jamesmontemagno

IeuanWalker commented 2 years ago

Thanks, @DevEddy, missed that one.

Before updating the NuGet, it was crashing following the steps above. And looking in the device log it was the same issue. After updating the NuGet I couldn't get it to crash following the same steps.

So fingers crossed the issue is solved 🤞

I will report back once we release a new version and see whether the number of crashes goes down or not

xleon commented 2 years ago

@IeuanWalker could you share your results in production?

FunbiOyede commented 2 years ago

Yeah @IeuanWalker any positive results yet?

IeuanWalker commented 2 years ago

@xleon @FunbiOyede

Not really :/

Our testers have 2 devices that can replicate the issue. The best we got was to update XF to the latest version. This prevents it from crashing, by restarting the app, so it is better than before. But ideal they should be returned to the original view.

But for now, that's the best we could do, due to other commitments.

Haven't published a new version to the stores yet, but crash reports should hopefully go down.

FunbiOyede commented 2 years ago

Ok. Thanks for your response

xleon commented 2 years ago

I had to update XF to latest due to this and other crashes in Android. Everything looks good on our local testing. I removed manual references to AndroidX packages, leaving the automatic dependencies from XF. Will go to production soon. Wish me luck 😁

EmilAlipiev commented 2 years ago

@xleon can you share your android.csproj nuget overview (for Android packages)?

xleon commented 2 years ago
<PackageReference Include="AppboyPlatform.AndroidBinding" Version="1.21.1" />
    <PackageReference Include="AppsFlyerXamarinBindingAndroid" Version="6.3.2.2" />
    <PackageReference Include="Com.Airbnb.Xamarin.Forms.Lottie" Version="4.0.10" />
    <PackageReference Include="DryIoc.dll" Version="4.8.1" />
    <PackageReference Include="Fody" Version="6.5.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Plugin.CurrentActivity" Version="2.1.0.4" />
    <PackageReference Include="Polly" Version="7.2.2" />
    <PackageReference Include="ReactiveUI.Fody" Version="16.1.1" />
    <PackageReference Include="ReactiveUI.XamForms" Version="16.1.1" />
    <PackageReference Include="Rg.Plugins.Popup" Version="2.0.0.12" />
    <PackageReference Include="SegmentedControl.FormsPlugin" Version="2.0.1" />
    <PackageReference Include="Serilog.Sinks.Xamarin" Version="0.2.0.64" />
    <PackageReference Include="SQLiteNetExtensions" Version="2.1.0" />
    <PackageReference Include="sqlite-net-pcl" Version="1.7.335" />
    <PackageReference Include="Xamarin.AndroidX.Biometric" Version="1.1.0" />
    <PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
    <PackageReference Include="Xamarin.FFImageLoading.Forms" Version="2.4.11.982" />
    <PackageReference Include="Xamarin.FFImageLoading.Transformations" Version="2.4.11.982" />
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
    <PackageReference Include="Xamarin.Firebase.Messaging" Version="121.0.1" />
    <PackageReference Include="Xamarin.Forms.GoogleMaps" Version="4.0.0-BETA1" />
    <PackageReference Include="Xamarin.Forms.SaveOpenPDFPackage" Version="1.0.0" />
    <PackageReference Include="Xamarin.Google.Dagger" Version="2.27.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.Base" Version="117.6.0" />
    <PackageReference Include="ZXing.Net.Mobile.Forms" Version="3.1.0-beta2" />
kcrg commented 2 years ago

@xleon You can remove Plugin.CurrentActivity nuget because Xamarin.Essentials have this functionality. Small tip from me :)