1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
android_webview / docs / quick-start-legacy.md [blame]
# WebView quick start (legacy)
*** note
This is an old version of the quick start guide. We recommend following the [new
version instead](./quick-start.md).
***
[TOC]
## Overview
This is not a thorough guide for how to build WebView, but is the **fastest**
way to get a local build of WebView up and running.
### Building for preview Android releases
Googlers should see internal instructions. External contributors should switch
to a public (and finalized) Android release (there's no workaround).
## System requirements, tools, etc.
See general Android instructions for:
* [System
requirements](/docs/android_build_instructions.md#System-requirements)
* [Installing
`depot_tools`](/docs/android_build_instructions.md#Install-depot_tools)
* [Getting the code](/docs/android_build_instructions.md#Get-the-code) **or**
[converting a Linux
checkout](/docs/android_build_instructions.md#Converting-an-existing-Linux-checkout)
* [Installing build
dependencies](/docs/android_build_instructions.md#Install-additional-build-dependencies)
**and** [running hooks](/docs/android_build_instructions.md#Run-the-hooks)
## Install adb
If you don't already have `adb` installed, the fastest way is to add chromium's
Android SDK to your `$PATH`. If you use multiple terminal, you'll want to run
this command in each terminal:
```shell
$ source build/android/envsetup.sh
```
## Device setup
The recommend configuration is to use an **Android P emulator**. Android N or O
are also OK, however if you need to use any other OS version then you need to
switch to the full [build guide](./build-instructions.md) instead.
Set up an [Android emulator](/docs/android_emulator.md). You have 2 options for
this:
1. Preconfigured emulator image. Just run this command in your terminal, which
will launch an emulator window when the emulator is ready. If anything goes
wrong, see [the
documentation](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/android_emulator.md#Using-Prebuilt-CIPD-packages)
or try the next option (see below).
```shell
$ tools/android/avd/avd.py start \
--avd-config tools/android/avd/proto/generic_android28.textpb --emulator-window
```
2. Android Studio Emulator image. [Install the Android Studio
IDE](https://developer.android.com/studio/install) and then follow [these
instructions](https://developer.android.com/studio/run/managing-avds)
to launch the Device Manager GUI. Create an emulator with these settings:
* Skin: any Pixel device skin is fine
* Release name: **Pie**
* ABI: **x86**
* Target: **Google APIs**
<!-- Keep this part in sync with /docs/android_emulator.md -->
* Select "Show Advanced Settings" > scroll down:
* Set internal storage to 4000MB
* Set SD card to 1000MB
* If in doubt, consult the
[chromium
documentation](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/android_emulator.md#Using-Your-Own-Emulator-Image)
to configure your emulator
Once configured, click the **play** button to launch the emulator.
**Verify your emulator is ready:** after performing either of the steps above,
you should check your emulator by running:
```shell
# If everything worked correctly, this should say "device" in the right column.
$ adb devices
List of devices attached
emulator-5554 device
```
## Setting up the build
Configure GN args (run `gn args out/Default`) as follows:
```gn
target_os = "android"
target_cpu = "x86"
# This package name is allowed for debuggable (userdebug) devices, and lets
# devs install a WebView provider without the usual signature checks. This only
# works on N-P.
system_webview_package_name = "com.google.android.apps.chrome"
# Recommended: this lets you use System WebView Shell as a test app.
system_webview_shell_package_name = "org.chromium.my_webview_shell"
```
## Build, install, and switch WebView provider {#build}
```shell
# Build
$ autoninja -C out/Default system_webview_apk
# 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
```
**That's it!** Your APK should be installed and should be providing the WebView
implementation for all apps on the system.
## Things to do next
### Start running an app
**Skip this section** if you already have an app you want to test.
You can start testing our your WebView APK with the System WebView Shell test
app. This also shows the WebView version at the top of the app, so you can
verify this is using the version you built locally. You can run this test app
like so:
```shell
# Build
$ autoninja -C out/Default system_webview_shell_apk
# Install
$ out/Default/bin/system_webview_shell_apk install
# Launch a URL
$ out/Default/bin/system_webview_shell_apk launch "https://www.google.com/"
```
For more info about WebView Shell, see [the docs](./webview-shell.md).
### Toggle features or commandline flags
**Skip this section** if you don't need to toggle a specific commandline flag.
If you exposed your flag in [ProductionSupportedFlagList.java], then you can
toggle the flag in WebView DevTools. For more info about WebView DevTools, see
[the docs](./developer-ui.md). You can launch WebView DevTools with:
```shell
$ adb shell am start -a "com.android.webview.SHOW_DEV_UI"
```
If the flag is not exposed, you can instead try following [these
steps](./commandline-flags.md).
### Debug with adb logcat
We recommend starting with "printf-style debugging" on Android:
1. Add some logs in your code:
* In C++ code: add `LOG(ERROR) << "SOMETAG: <your log message goes here>";`
* In Java code: add `org.chromium.base.Log.e("SOMETAG", "<your log message
goes here>");`
2. Recompile and reinstall `system_webview_apk` (see
[steps above](#build)). Re-launch your test app.
3. Read your log messages by running this command:
`adb logcat | grep 'SOMETAG'`
For more guidance, refer to [the logging
documentation](/docs/android_logging.md).
### Run automated tests
We recommend starting with [integration
tests](./test-instructions.md#instrumentation-tests).
### Shutdown your emulator when you're done
The recommended way to turn off your emulator is to just close the emulator
window. If that doesn't work or you can't find the emulator window, then you can
safely shutdown your emulator by running `adb emu kill` in the terminal.
## Troubleshooting
If the install command succeeded but something else is wrong, the best way to
troubleshoot the problem is to query the state of the on-device
WebViewUpdateService:
```shell
# Only available on O+
$ adb shell dumpsys webviewupdate
Current WebView Update Service state
Fallback logic enabled: true
Current WebView package (name, version): (com.google.android.apps.chrome, 75.0.3741.0)
Minimum WebView version code: 303012512
Number of relros started: 1
Number of relros finished: 1
WebView package dirty: false
Any WebView package installed: true
Preferred WebView package (name, version): (com.google.android.apps.chrome, 75.0.3741.0)
WebView packages:
Valid package com.android.chrome (versionName: 58.0.3029.125, versionCode: 303012512, targetSdkVersion: 26) is installed/enabled for all users
Valid package com.google.android.webview (versionName: 58.0.3029.125, versionCode: 303012500, targetSdkVersion: 26) is NOT installed/enabled for all users
Invalid package com.chrome.beta (versionName: 74.0.3729.23, versionCode: 372902311, targetSdkVersion: 28), reason: No WebView-library manifest flag
Invalid package com.chrome.dev (versionName: 54.0.2840.98, versionCode: 284009811, targetSdkVersion: 24), reason: SDK version too low
Invalid package com.chrome.canary (versionName: 75.0.3741.0, versionCode: 374100010, targetSdkVersion: 25), reason: SDK version too low
Valid package com.google.android.apps.chrome (versionName: 75.0.3741.0, versionCode: 2, targetSdkVersion: 28) is installed/enabled for all users
```
### Invalid package ... No WebView-library manifest flag
This APK does not contain a WebView implementation. Make sure you're building
`system_webview_apk`.
### Invalid package ... Version code too low
This shouldn't happen for userdebug builds. If it does, add this GN arg:
```gn
# Any number >= "Minimum WebView version code":
android_override_version_code = "987654321"
```
### Invalid package ... SDK version too low
The targetSdkVersion of your APK is too low (it must be >= the platform's API
level). This shouldn't happen for local builds using tip-of-tree chromium on
public OS versions (see [note](#Building-for-preview-Android-releases)).
*** note
**Note:** we only support local development using the latest revision of the
main branch. Checking out release branches introduces a lot of complexity, and
it might not even be possible to build WebView for your device.
***
### Invalid package ... Incorrect signature
This shouldn't happen for userdebug devices, and there's no workaround for user
devices. Make sure you have a userdebug device (you can check with `adb shell
getprop ro.build.type`).
### Valid package ... **is** installed/enabled for all users
This is the correct state. If this is not the "preferred WebView package" or the
"current WebView package", call `set-webview-implementation` again.
### Valid package ... **is NOT** installed/enabled for all users
This shouldn't happen for `com.google.android.apps.chrome` (the recommended
package name). If you need to use a different package name, you may be able to
workaround this by enabling "redundant packages" (`adb shell cmd webviewupdate
enable-redundant-packages`), reinstalling, and running `set-webview-provider`
again.
Otherwise, please [reach out to the team][1].
### My package isn't in the list
Either your package didn't install (see below) or you chose a package name which
is [not eligible as a WebView provider](webview-providers.md#Package-name) for
this device. Double-check the package name in your GN args. If you're on AOSP
(any OS level), choose `"com.android.webview"`. If you're on L-M, choose
`"com.google.android.webview"`. In either case, you'll likely need to [remove
the preinstalled WebView
APK](/android_webview/tools/remove_preinstalled_webview.py).
### WebView shell doesn't show the correct version
Check the "Current WebView package" in the dumpsys output. You're probably
hitting one of the cases above.
### INSTALL\_FAILED\_UPDATE\_INCOMPATIBLE: Package ... signatures do not match previously installed version
This is probably because you've already installed Chrome Debug (ex. with the
Google-only `monochrome_apk` target, or through a Google-only official build).
This guide borrows that app's package name, but the locally compiled APK may not
have the same signing key, causing the `adb install` error. You should remove
the conflicting package with `out/Default/bin/system_webview_apk uninstall`, and
then try installing WebView again.
### I couldn't install the APK/... is NOT installed.
This could fail for an even wider variety of reasons than already listed. Please
[reach out to the team][1].
### I couldn't **build** the APK
Try building Chromium. If that doesn't work, please reach out to [the chromium
team](https://groups.google.com/a/chromium.org/forum/#!forum/chromium-dev) for
general guidance. If `system_webview_apk` is the only troublesome target, please
reach out to the WebView team (see previous section).
## What if I didn't follow these instructions exactly?
**Proceed at your own risk.** Building and installing WebView is, for a variety
of reasons, complex. If you've deviated from **any** of these instructions (and
don't know what you're doing) there's a good chance of making mistakes (some of
which don't have any error messages).
If you can't follow the quick start guide for some reason, please consult our
[general build instructions](build-instructions.md).
[1]: https://groups.google.com/a/chromium.org/forum/#!forum/android-webview-dev
[ProductionSupportedFlagList.java]: https://source.chromium.org/chromium/chromium/src/+/main:android_webview/java/src/org/chromium/android_webview/common/ProductionSupportedFlagList.java