4

The GeckoEngineView fails to be inflated, despite using latest dependencies.

The code is from an official documentation on GeckoView. All the latest dependencies and repos have been successfully resolved in the project.

The Error:

Error inflating class mozilla.components.browser.engine.gecko.GeckoEngineView

Upon scouring the error log:

 Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class mozilla.components.browser.engine.gecko.GeckoEngineView
 Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class mozilla.components.browser.engine.gecko.GeckoEngineView
 Caused by: java.lang.ClassNotFoundException: Didn't find class "mozilla.components.browser.engine.gecko.GeckoEngineView" on path: DexPathList[[zip file "/data/app/com.geckoengine.example-IQhwqfpsfzKO11EI9ak6kQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.geckoengine.example-IQhwqfpsfzKO11EI9ak6kQ==/lib/arm64, /data/app/com.geckoengine.example-IQhwqfpsfzKO11EI9ak6kQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]

Updated XML File, Credit: @ArturoMejia
activity_main.xml:

<org.mozilla.geckoview.GeckoView
    android:id="@+id/geckoview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

MainActivity.java

public class MainActivity extends AppCompatActivity {

    GeckoView view;
    GeckoSession session;
    GeckoRuntime runtime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        view = findViewById(R.id.geckoview);
        session = new GeckoSession();
        runtime = GeckoRuntime.create(this);
        session.open(runtime);
        view.setSession(session);


        //TODO: add any url
        //TODO: Use intent.putExtraString() to send a url from the main activity to this activity
        session.loadUri("http://theyouthbuzz.com/");
    }
}

The documentation implies that the code should load a webview without any problems. The same is not verifiable.

Notes:

Android studio version: 3.5 RC 3 [dev channel]

SowingFiber
  • 1,194
  • 1
  • 12
  • 32

3 Answers3

4

@SowingFiber I think you have a small error, on the XML code on the example above, possible in the last edition. I think you should update it because, as it's now, it is not going to compile.

The problem is that you have two different types of references, one in the XML and another in the code. To match the reference in the code, you have to use org.mozilla.geckoview.GeckoView in the XML.

<org.mozilla.geckoview.GeckoView
    android:id="@+id/geckoview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

Additionally you could include geckoview directly, without using Mozilla Android Components, in case you just want to use geckoview.

implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}:${geckoviewVersion}"   
Arturo Mejia
  • 1,862
  • 1
  • 17
  • 25
2

As described in the component doc to use it you have to add this dependencies in your build.gradle

implementation "org.mozilla.components:browser-engine-gecko:{latest-version}"

Currently the latest version is 9.0.0

implementation "org.mozilla.components:browser-engine-gecko:9.0.0"
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

You need to override this onCreateView of your actvity

override fun onCreateView(parent: View?, name: String?, context: Context, attrs: AttributeSet?): View? = when (name) {
       EngineView::class.java.name -> engine.createView(context, attrs).asView()
       else -> super.onCreateView(parent, name, context, attrs)
}