Daddoon / Xamarin.Android.GeckoView

A NuGet package and an example project to embed a GeckoView in your Xamarin Android App
MIT License
4 stars 1 forks source link

Failed to initialize GeckoRuntime - Xamarin Forms #16

Closed Galle94 closed 5 years ago

Galle94 commented 5 years ago

When opening the page with GeckoView for the second time, throw the following exception.

Unhandled Exception: Java.Lang.IllegalStateException: Failed to initialize GeckoRuntime

The first time when open the page it work perfectly, but when go back in navigation and get in again it fail.

Specs

  • Xamarin.Forms v4.1.0.581479

  • Xamarin.Android.GeckoView v0.0.1 (only Android Project)

  • Xamarin.Android.GeckoView.Forms v0.0.1 (Android, Shared)

  • Android Target: Android Pie 9.0

  • PCL Target: Net Standard 2.0.3

MainActivity -> OnCreate

public class MainActivity : MvxFormsAppCompatActivity<StartUpViewModel>
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            GeckoViewRenderer.Init(this);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            FormsMaterial.Init(this, savedInstanceState);

            LoadApplication(new App());
        } 
}

PortCostsPage.cs

public PortCostsPage()        
{
            InitializeComponent();
            var view= new GeckoViewForms
            {
                Source = "web page url..."
            };
            view.HorizontalOptions = LayoutOptions.FillAndExpand;
            view.VerticalOptions = LayoutOptions.FillAndExpand;
            stack.Children.Add(view);
}

Debug Console

Thread started: #9 08-02 04:23:21.221 W/GeckoFontScaleListener(21207): Already attached! 08-02 04:23:21.222 W/GeckoRuntime(21207): init failed (could not initiate GeckoThread) 08-02 04:23:21.861 I/anyname.AMSTes(21207): Background concurrent copying GC freed 7072(672KB) AllocSpace objects, 23(460KB) LOS objects, 49% free, 1855KB/3MB, paused 29.778ms total 140.709ms Unhandled Exception:

Java.Lang.IllegalStateException: Failed to initialize GeckoRuntime

08-02 04:23:25.923 E/GeckoProcessManager(21207): Cannot connect to process tab [Parent 21207, IPC Launch #1] WARNING: Failed to launch tab subprocess: file /builds/worker/workspace/build/src/ipc/glue/GeckoChildProcessHost.cpp, line 588 [Parent 21207, Gecko_IOThread] WARNING: pipe error (88): Connection reset by peer: file /builds/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 35708-02 04:23:25.923 I/Gecko (21207): [Parent 21207, IPC Launch #1] WARNING: Failed to launch tab subprocess: file /builds/worker/workspace/build/src/ipc/glue/GeckoChildProcessHost.cpp, line 588

08-02 04:23:25.924 I/Gecko (21207): [Parent 21207, Gecko_IOThread] WARNING: pipe error (88): Connection reset by peer: file /builds/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 357

Greetings!

Daddoon commented 5 years ago

Sorry, i didn't seen your issue as i forgot to subscribe to all notification on my repository. I'm taking a look about your issue.

Daddoon commented 5 years ago

Can you give me more info about your issue ?

When you say "When opening the page with GeckoView for the second time, throw the following exception.", what do you mean by this ?

  1. You changed the URL source
  2. You navigated to another URL
  3. You created another GeckoView component ?

I'm actually shipping an update as i have seen that the Xamarin.Forms component does not change URI when Source is changed. I didn't have seen any crash during my tests.

Galle94 commented 5 years ago

Thanks for reply!!

I mean when I navigate to the page with GeckoView component, go back and navigate again.

I could locate the line when it threw the exception and is GeckoRuntime _runtime = GeckoRuntime.Create(Context);

I think when it initialize the GeckoView component for the second time it fail.

I solve it creating a CustomGeckoViewRenderer and overriding CreateNewSession Method.

public override Tuple<GeckoSession, GeckoRuntime> CreateNewSession()
{
       GeckoSession _session = new GeckoSession();
       GeckoRuntime _runtime = GeckoRuntime.GetDefault(Context);

       _session.Open(_runtime);

       return Tuple.Create(_session, _runtime);
}

I don't know if it's the best option but it works like a charm

Greetings!

Daddoon commented 5 years ago

Well it's very strange, i would imagine that if you go back and go on GeckoView again, the component would be totally cleared as it has been disposed by you going back.

I'm wondering if something is happning about the current Android context ?

I will take a look maybe in few days, as i'm already working on other things during the week. Thanks for your feedback and your own workaround.

I will see if there is something that is staling somewhere in the component.

Daddoon commented 5 years ago

This or there is something wrong with the current GeckoView android build. I know that newer version have some additionnals dependency about app lifecycle and some other things, maybe there is some evolutions.

I don't have upgraded the GeckoView component because somehow signatures have changed in the new version, and i have a lot of difficulty to generate the same delegates class API from GeckoView with the new version.

Android java bindings for Xamarin are a pain ! :p

Daddoon commented 5 years ago

You were right about the GeckoRuntime.GetDefault(Context); call. I have search some doc and related comments on this thing (some are from 2 years ago). It seem that:

Also reading documentation, i have seen there is also an issue in the default OnNewSession method written in the NavigationDelegate i provide. The documentation state that the newly created session from this call must not be opened, and also the object must be referenced somewhere to not be garbage collected.

I have made modification, that i will ship very soon. Thanks for your feedback !