android_webview/docs/build-instructions.md
*** promo Building WebView for the first time? Please see the quick start guide first.
[TOC]
This is meant to be a comprehensive guide for building WebView, within the limits of what is possible in a public chromium checkout. While this is sufficient for most cases, Googlers may wish to consult internal instructions to get a checkout including closed-source code, which is necessary if:
system_webview_google_apk),
orSee general Android instructions for:
depot_toolsFor the minimum requirements, please see Device Setup.
Configure GN args (run gn args out/Default) as follows:
target_os = "android"
# See "Figuring out target_cpu" below
target_cpu = "arm64"
# Not always necessary, see "Changing package name" below
system_webview_package_name = "..."
# Optional: speeds up build time. For instructions, refer to
# https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md#use-reclient
use_remoteexec = true
Please see the Chromium instructions.
Similarly to Chrome, WebView can be compiled with a variety of build targets.
TODO(crbug.com/41454956): document the differences between each target.
First, you should figure out your device's integer API level, which determines which build targets will be compatible with the version of the OS on your device:
adb shell getprop ro.build.version.sdk
*** promo Tip: you can convert the API level integer to the release's dessert codename with this table. This developer guide uses API integers and release letters interchangeably.
Then you can build one of the following targets:
autoninja -C out/Default system_webview_apk
*** promo
Note: We focus on system_webview_apk rather than Trichrome because we
ship WebView separately from Chrome for stability reasons. This reduces start
up time and reduces ANRs. You may see references to Trichrome but this should
be considered a historical artefact.
Unlike most Android apps, WebView is part of the Android framework. One of the consequences of this is that the WebView implementation on the device can only be provided by a predetermined set of package names (see details). Depending on the chosen build target, you may need to change the package name to match one of the following:
<!-- Keep this table in sync with webview-providers.md -->| API level | Has GMS vs. AOSP? | Allowed package names |
|---|---|---|
| >= Q | AOSP | com.android.webview (default, preinstalled) |
| >= Q | Has GMS | com.google.android.webview (default, preinstalled) |
com.google.android.webview.beta | ||
com.google.android.webview.dev | ||
com.google.android.webview.canary | ||
com.google.android.webview.debug (only userdebug/eng) | ||
com.android.webview (only userdebug/eng) |
system_webview_apk uses com.android.webview as the package name by
default. If your device allows this package name, continue to the next
section. Otherwise, you can change the package
name by setting the system_webview_package_name GN arg (ex.
system_webview_package_name = "com.google.android.webview").
See internal instructions for the Google-internal build targets
(system_webview_google_apk).
*** note
Note: TV/car devices have a bug where the release key signed WebView is
preinstalled on all Android images, even those signed with dev-keys. Because
humans cannot access release keys (use_signing_keys = true provides "developer
test keys," not release keys), you must remove the preinstalled WebView (see
below).
If WebView is preinstalled (under the chosen package name) in the device's system image, you'll also need to remove the preinstalled APK (otherwise, you'll see signature mismatches when installing). You can skip this step if You chose a package name which is not marked as "(preinstalled)."
Otherwise, you can remove the preinstalled WebView like so:
android_webview/tools/remove_preinstalled_webview.py
*** note
If you're using an emulator, make sure to start it with
-writable-system
before removing the preinstalled WebView.
If the script doesn't work, see the manual steps.
For help connecting your Android device, see the Chromium instructions.
You can install a locally compiled APK like so:
# Install the APK
out/Default/bin/system_webview_apk install
# Tell Android platform to load a WebView implementation from this APK
out/Default/bin/system_webview_apk set-webview-provider
See Start running an app from the quick start.
Please see the Troubleshooting section in the quick start.
TODO(ntfschr): document cases here which could arise generally, but wouldn't for the quick start.