Mobile/GeckoView: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(→‎Testing GeckoView: Mention IRC channel and Google Group)
m (→‎Testing GeckoView: Add tip about leaving Focus beta program)
Line 11: Line 11:
GeckoView is a library, not a standalone app, but you can test GeckoView by installing Focus Nightly "track" (channel). Focus 6.0 and earlier use Android's WebView, but Focus 7.0 is switching to Mozilla's homegrown Gecko. Unfortunately, Google Play only allows you to install one track (per Google Play account) at a time. Installing Focus Nightly will uninstall the regular Focus and replace it (and your settings) with Focus Nightly. If you have multiple Google Play accounts, then you can install a different Focus track in each account.
GeckoView is a library, not a standalone app, but you can test GeckoView by installing Focus Nightly "track" (channel). Focus 6.0 and earlier use Android's WebView, but Focus 7.0 is switching to Mozilla's homegrown Gecko. Unfortunately, Google Play only allows you to install one track (per Google Play account) at a time. Installing Focus Nightly will uninstall the regular Focus and replace it (and your settings) with Focus Nightly. If you have multiple Google Play accounts, then you can install a different Focus track in each account.


* [https://github.com/mozilla-mobile/focus-android/wiki/Release-tracks How to install Focus Nightly]
* [https://github.com/mozilla-mobile/focus-android/wiki/Release-tracks#nightly How to install Focus Nightly]
* If you have questions, you're welcome to drop by the #focus IRC channel on [https://wiki.mozilla.org/IRC Mozilla's IRC server] or ask in the [https://groups.google.com/forum/#!forum/focus-klar-nightly focus-klar-nightly Google Group].
* If you have questions, you're welcome to drop by the #focus IRC channel on [https://wiki.mozilla.org/IRC Mozilla's IRC server] or ask in the [https://groups.google.com/forum/#!forum/focus-klar-nightly focus-klar-nightly Google Group].
** * If you've found a bug in Focus Nightly compared to Focus using WebView, then check the [https://github.com/mozilla-mobile/focus-android/issues Focus bug tracker] to see if there is a bug filed. If not, please file one! :)
* If you've found a bug in Focus Nightly compared to Focus using WebView, then check the [https://github.com/mozilla-mobile/focus-android/issues Focus bug tracker] to see if there is a bug filed. If not, please file one! :)
 
If you joined the Focus beta program ''before'' subscribing to the focus-klar-nightly Google Group, Google Play might not upgrade you to the new Focus Nightly right away. In this case, try leaving the Focus beta program (by clicking the "LEAVE" button in the "You're a beta tester" section of Focus's Google Play page), uninstalling Focus, re-joining the beta program, and then re-installing Focus. Google Play treats the Focus beta and nightly tracks as different flavors of beta and can forget to switch you from the regular beta to the nightly "beta" track.


== Using GeckoView ==
== Using GeckoView ==

Revision as of 17:43, 29 June 2018

What is GeckoView

GeckoView is an Android library project that allows third-party developers to use Gecko as an Android View in their own applications. GeckoView is similar to Android's built in WebView, but it is not a drop in replacement for WebView.

Note that GeckoView is not quite ready to be used in a production environment.

Current API documentation can be viewed here: https://mozilla.github.io/geckoview/javadoc/mozilla-central/

Testing GeckoView

GeckoView is a library, not a standalone app, but you can test GeckoView by installing Focus Nightly "track" (channel). Focus 6.0 and earlier use Android's WebView, but Focus 7.0 is switching to Mozilla's homegrown Gecko. Unfortunately, Google Play only allows you to install one track (per Google Play account) at a time. Installing Focus Nightly will uninstall the regular Focus and replace it (and your settings) with Focus Nightly. If you have multiple Google Play accounts, then you can install a different Focus track in each account.

If you joined the Focus beta program before subscribing to the focus-klar-nightly Google Group, Google Play might not upgrade you to the new Focus Nightly right away. In this case, try leaving the Focus beta program (by clicking the "LEAVE" button in the "You're a beta tester" section of Focus's Google Play page), uninstalling Focus, re-joining the beta program, and then re-installing Focus. Google Play treats the Focus beta and nightly tracks as different flavors of beta and can forget to switch you from the regular beta to the nightly "beta" track.

Using GeckoView

Add Nightly taskcluster repo to your build.gradle

repositories {
    maven {
       url 'https://index.taskcluster.net/v1/task/gecko.v2.mozilla-central.nightly.latest.mobile.android-api-16-opt/artifacts/public/android/maven'
    }
}

Add geckoview to dependencies

Again, in build.gradle

dependencies {
    implementation 'org.mozilla:geckoview-nightly-armeabi-v7a:+'
}

This will always use the latest Nightly in the repository. As GeckoView development continues, we will have Beta and Release repositories that have the expected version names (61.0.0, etc).

Loading a page in GeckoView

You can now use GeckoView your app by including the following in a layout XML file:

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

You can then load a page in your Activity with:

onCreate(...) {
    // Find the GeckoView in our layout
    GeckoView geckoView = (GeckoView) findViewById(R.id.geckoview);

    // Attach the GeckoView to a new GeckoSession
    GeckoSession session = new GeckoSession();
    session.open();
    geckoView.setSession(session);

    // Load a URL
    session.loadUri("http://mozilla.com");
}

Example App

GeckoViewExample is an example app that lives in mozilla-central and lets you easily exercise GeckoView. You can build/install it with the following gradle command:

mach gradle geckoview_example:installLocalWithGeckoBinariesNoMinApiDebug

You may find it easier to do this from Android Studio, where geckoview_example appears as a module.

Firefox Focus also has a build variant that uses Gecko. To build, check out the Focus code from https://github.com/mozilla-mobile/focus-android and follow the instructions. The only difference is you need to select one of the Gecko build variants from the Android Studio 'Build' menu.

The Gecko-related code for Focus lives in WebViewProvider.java

Bugs

GeckoView bugs 🐛