Mobile/GeckoView: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Fixing link to contributor quick start guide)
(https://bugzilla.mozilla.org/show_bug.cgi?id=1508976 introduced a single multi-architecture AAR for GeckoView, but our Quick Start guide still refers to setting up multiple architectures. This needs to be updated to reflect the existing requirements.)
Line 27: Line 27:


=== Configure Gradle ===
=== Configure Gradle ===
You need to add or edit four stanzas inside your module's <code>build.gradle</code> file.


'''1. Set the GeckoView version'''
'''1. Set the GeckoView version'''
Line 36: Line 34:
ext {
ext {
     geckoviewChannel = "nightly"
     geckoviewChannel = "nightly"
     geckoviewVersion = "64.0.20180927100037"
     geckoviewVersion = "70.0.20190712095934"
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 49: Line 47:
</syntaxhighlight>
</syntaxhighlight>


'''3. Configure build flavors'''
'''3. Configure Java 8 support'''
 
''Note: Until we resolve [https://bugzilla.mozilla.org/show_bug.cgi?id=1485045 Bug 1485045], you must configure a separate build variant for each CPU architecture.''


<syntaxhighlight lang="Groovy">
<syntaxhighlight lang="Groovy">
Line 61: Line 57:
         sourceCompatibility JavaVersion.VERSION_1_8
         sourceCompatibility JavaVersion.VERSION_1_8
         targetCompatibility JavaVersion.VERSION_1_8
         targetCompatibility JavaVersion.VERSION_1_8
    }
    flavorDimensions "abi"
    productFlavors {
        x86    { dimension "abi" }
        x86_64  { dimension "abi" }
        arm    { dimension "abi" }
        aarch64 { dimension "abi" }
     }
     }
}
}
Line 78: Line 65:
dependencies {
dependencies {
     // ...
     // ...
 
     implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}:${geckoviewVersion}"  
     x86Implementation    "org.mozilla.geckoview:geckoview-${geckoviewChannel}-x86:${geckoviewVersion}"
    x86_64Implementation  "org.mozilla.geckoview:geckoview-${geckoviewChannel}-x86_64:${geckoviewVersion}"
    armImplementation    "org.mozilla.geckoview:geckoview-${geckoviewChannel}-armeabi-v7a:${geckoviewVersion}"
    aarch64Implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}-arm64-v8a:${geckoviewVersion}"
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 141: Line 124:


'''Products / Examples'''
'''Products / Examples'''
* [https://blog.mozilla.org/futurereleases/2019/06/27/reinventing-firefox-for-android-a-preview/ Firefox Preview] ([https://github.com/mozilla-mobile/fenix GitHub])
* [https://blog.mozilla.org/blog/2018/09/18/firefox-reality-now-available/ Firefox Reality] ([https://github.com/mozillareality/firefoxreality GitHub])
* [https://blog.mozilla.org/blog/2018/09/18/firefox-reality-now-available/ Firefox Reality] ([https://github.com/mozillareality/firefoxreality GitHub])
* [https://www.mozilla.org/firefox/mobile/#focus Firefox Focus] ([https://github.com/mozilla-mobile/focus-android/ GitHub])
* [https://www.mozilla.org/firefox/mobile/#focus Firefox Focus] ([https://github.com/mozilla-mobile/focus-android/ GitHub])

Revision as of 01:13, 16 July 2019

GeckoView wraps Mozilla's Gecko browser engine in a reusable Android library.

Mozilla uses GeckoView to power Firefox Reality, Firefox Focus, and other Android apps. GeckoView serves a similar purpose to Android's built-in WebView, but it has its own APIs and is not a drop in replacement.

Why GeckoView?

While Android offers a built-in WebView, it's not intended for building browsers, and many advanced Web APIs are disabled. Android's WebView is also a moving target: it's impossible know exactly which engine (and what version of that engine) will power a WebView on client devices.

In contrast, GeckoView is:

  • Full-Featured: GeckoView is designed to expose the entire power of the Web to applications, including being suitable for building web browsers.
  • Self-Contained: Because GeckoView is a standalone library that you bundle with your application, you can be confident that the code you test is the code that will actually run.
  • Standards Compliant: Like Firefox, GeckoView offers excellent support for modern Web standards.

Getting Help

Interested in GeckoView? We're here to help!

If you have questions or need assistance, please reach out by:

Get Started

Building a browser? Check out Android Components, our collection of ready-to-use support libraries!

Configure Gradle

1. Set the GeckoView version

Like Firefox, GeckoView has three release channels: Stable, Beta, and Nightly. Browse the Maven Repository to see currently available builds.

ext {
    geckoviewChannel = "nightly"
    geckoviewVersion = "70.0.20190712095934"
}

2. Add Mozilla's Maven repository

repositories {
    maven {
        url "https://maven.mozilla.org/maven2/"
    }
}

3. Configure Java 8 support

android {
    // ...

    // Note: compileOptions is only required for minSdkVersion < 24
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

4. Add GeckoView Implementations

dependencies {
    // ...
    implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}:${geckoviewVersion}"   
}

Add GeckoView to a Layout

Inside a layout .xml file, add the following:

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

Initialize GeckoView in an Activity

1. Import the GeckoView classes inside an Activity:

import org.mozilla.geckoview.GeckoRuntime;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoView;

2. In that activity's onCreate function, add the following:

GeckoView view = findViewById(R.id.geckoview);
GeckoSession session = new GeckoSession();
GeckoRuntime runtime = GeckoRuntime.create(this);

session.open(runtime);
view.setSession(session);
session.loadUri("about:buildconfig"); // Or any other URL...

You're done!

Your application should now load and display a webpage inside of GeckoView.

To learn more about GeckoView's capabilities, review GeckoView's JavaDoc or the reference application.

Documentation and Examples

APIs

Building / Contributing

Bugs

Products / Examples

Minimum System Requirements

  • GeckoView requires Android OS version 4.3 (API Level 18) or later. For comparison, Fennec supports Android 4.1 (API level 16) and later. Fenix and Focus support Android 5.0 (API level 21) and later.
  • 32-bit ARMv7-A, 64-bit ARMv8-A (aka ARM64), 32-bit x86, or x86_64 CPU
  • Minimum device specs are quad-core 1.2 GHz and 2 GB RAM (like the Moto G4 Play, E4, or E5), though Mozilla's GeckoView test devices are the Moto G5 with an octa-core 1.4 GHz CPU and 2 GB RAM and the Google Pixel 2 with an octa-core 1.9 GHz CPU and 4 GB RAM.