# Getting Started with GeckoView

How to use GeckoView in your Android app.

*Building a browser? Check out* [Android Components](https://mozilla-mobile.github.io/firefox-android/), *our collection of ready-to-use support libraries!*

The following article is a brief guide to embedding GeckoView in an app. For a more in depth tutorial on getting started with GeckoView please read the article we have published on [raywenderlich.com](https://www.raywenderlich.com/1381698-android-tutorial-for-geckoview-getting-started).

```{contents}
:local: true
```

## Configure Gradle

You need to add or edit four stanzas inside your module's `build.gradle` file.

## 1. Set the GeckoView version

*Like Firefox, GeckoView has three release channels: Stable, Beta, and Nightly. Browse the* [Maven Repository](https://maven.mozilla.org/?prefix=maven2/org/mozilla/geckoview/) *to see currently available builds.*

```groovy
ext {
    geckoviewChannel = <channel>
    geckoviewVersion = <version>
}
```

## 2. Add Mozilla's Maven repository

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

## 3. Java 17 required support

As GeckoView uses some Java 17 APIs, it requires these compatibility flags:

```groovy
compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
```

## 4. Add GeckoView Implementations

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

## Add GeckoView to a Layout

Inside a layout `.xml` file, add the following:

```xml
<org.mozilla.geckoview.GeckoView
    xmlns:android="http://schemas.android.com/apk/res/android"
    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:**

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

**2. Create a \`\`static\`\` member variable to store the \`\`GeckoRuntime\`\` instance.**

```java
private static GeckoRuntime sRuntime;
```

**3. In that activity's** `onCreate` **function, add the following:**

```java
GeckoView view = findViewById(R.id.geckoview);
GeckoSession session = new GeckoSession();

// Workaround for Bug 1758212
session.setContentDelegate(new GeckoSession.ContentDelegate() {});

if (sRuntime == null) {
  // GeckoRuntime can only be initialized once per process
  sRuntime = GeckoRuntime.create(this);
}

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

**4. Set the** [windowSoftInputMode](https://developer.android.com/guide/topics/manifest/activity-element#wsoft) **to** `adjustResize` **for** [interactive-widget](https://drafts.csswg.org/css-viewport/#interactive-widget-section) **:**

```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <activity android:name=".YourActivity"
              android:windowSoftInputMode="stateUnspecified|adjustResize" />
</manifest>
```

## 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](https://mozilla.github.io/geckoview/javadoc/mozilla-central/) or the {searchfox}`reference application <mobile/android/geckoview_example>`.
