For Developers‎ > ‎How-Tos‎ > ‎

Build Instructions (Android WebView)

For googlers, see internal instructions.

Summary

These are instructions for building the Android WebView. These instructions are necessary if you wish to run the WebView code as an Android system component (which is useful when working on performance or application compatibility). To run tests and for certain development tasks it is sufficient to use the standalone test shell as described here.

Device/emulator setup

Please read the documentation committed in chromium markdown: https://chromium.googlesource.com/chromium/src/+/HEAD/android_webview/docs/device-setup.md

Prerequisites

Being able to checkout and build Chrome for Android.

Building with ninja

Building

Follow the instructions here for getting the source and building chromium for android.
gn gen out/Release --args='target_os="android"'  # For 64-bit devices, use: --args='target_os="android" target_cpu="arm64"'
ninja -C out/Release system_webview_apk

Installing onto the device

There is a one time device set up to remove the existing webview. This is needed because it is not possible to install over the existing apk due to mismatched signing key.
# Uninstall any webview updates
adb uninstall com.google.android.webview  # May fail
adb uninstall com.android.webview  # May fail
# On M and up:
adb disable-verity; adb reboot

# Remove webview from system partition
adb root
adb remount
adb shell stop
adb shell rm -rf /system/app/webview /system/app/WebViewGoogle /system/app/WebViewStub
adb shell start
Install the built apk.
adb install -r -d out/Release/apks/SystemWebView.apk

Using an Emulator (x86)

  • Build with gn arg: target_cpu = "x86"
  • Hide system image webview (tested on api 21):

adb shell stop
adb shell mkdir /data/local/tmp/empty
adb shell mount -o bind /data/local/tmp/empty /system/app/webview
adb shell start
  • Install as above.

Test shell: system_webview_shell_apk

Please read the documentation committed in chromium markdown: https://chromium.googlesource.com/chromium/src/+/HEAD/android_webview/docs/webview-shell.md

Test shell: webview_instrumentation_apk

  • Simpler workflow: this embeds a copy of the AwContents (webview's internal core) in the apk rather than using the system webview, so you don't need to use a userdebug build.
  • Limitation: This is not real webview, so testability may be limited.
  • It is essentially a TestContainerView with a URL bar at the top and runs in hardware mode.
  • Build and install:
    ninja -C out/Default webview_instrumentation_apk
    adb install -r out/Default/apks/WebViewInstrumentation.apk
  • Open pages (http:// prefix is required, otherwise you'll get an empty page):
    out/Release/bin/webview_instrumentation_apk launch http://www.google.com
Comments