Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 1 | # WebView quick start |
| 2 | |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 3 | *** promo |
| 4 | Googlers may wish to consult http://go/clank-webview for Google-specific |
| 5 | developer guides. |
| 6 | *** |
| 7 | |
Nate Fischer | fdd8ca15 | 2019-06-12 03:24:38 | [diff] [blame] | 8 | [TOC] |
| 9 | |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 10 | ## Overview |
| 11 | |
| 12 | This is not a thorough guide for how to build WebView, but is the **fastest** |
| 13 | way to get a local build of WebView up and running. |
| 14 | |
| 15 | ### Building for preview Android releases |
| 16 | |
| 17 | Googlers should see internal instructions. External contributors should switch |
| 18 | to a public (and finalized) Android release (there's no workaround). |
| 19 | |
| 20 | ## System requirements, tools, etc. |
| 21 | |
| 22 | See general Android instructions for: |
| 23 | |
| 24 | * [System |
| 25 | requirements](/docs/android_build_instructions.md#System-requirements) |
Nate Fischer | 540458a | 2019-06-12 20:45:36 | [diff] [blame] | 26 | * [Installing |
| 27 | `depot_tools`](/docs/android_build_instructions.md#Install-depot_tools) |
Nate Fischer | fdd8ca15 | 2019-06-12 03:24:38 | [diff] [blame] | 28 | * [Getting the code](/docs/android_build_instructions.md#Get-the-code) **or** |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 29 | [converting a Linux |
Nate Fischer | fdd8ca15 | 2019-06-12 03:24:38 | [diff] [blame] | 30 | checkout](/docs/android_build_instructions.md#Converting-an-existing-Linux-checkout) |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 31 | * [Installing build |
Nate Fischer | fdd8ca15 | 2019-06-12 03:24:38 | [diff] [blame] | 32 | dependencies](/docs/android_build_instructions.md#Install-additional-build-dependencies) |
| 33 | **and** [running hooks](/docs/android_build_instructions.md#Run-the-hooks) |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 34 | |
| 35 | ## Device setup |
| 36 | |
| 37 | Easiest configuration is to choose a **Google APIs** emulator running **Android |
| 38 | N or higher**. See [Device Setup](./device-setup.md) for instructions. |
| 39 | |
| 40 | *** promo |
| 41 | **Android O or higher** comes with troubleshooting tools, so that's highly |
| 42 | recommended. |
| 43 | *** |
| 44 | |
| 45 | ## Setting up the build |
| 46 | |
Nate Fischer | fcb95a9 | 2019-05-31 22:58:38 | [diff] [blame] | 47 | Assuming you took the advice from above, configure GN args (run `gn args |
| 48 | out/Default`) as follows: |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 49 | |
| 50 | ```gn |
| 51 | # Minimal |
| 52 | target_os = "android" |
| 53 | target_cpu = "x86" # Assuming you chose an x86 emulator |
| 54 | |
Nate Fischer | 9df47c7 | 2020-07-01 20:57:33 | [diff] [blame] | 55 | # This package name is allowed for debuggable (userdebug) devices, and lets |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 56 | # devs install a WebView provider without the usual signature checks. This only |
| 57 | # works on N+. |
| 58 | system_webview_package_name = "com.google.android.apps.chrome" |
| 59 | ``` |
| 60 | |
| 61 | ## Build WebView |
| 62 | |
| 63 | ```shell |
| 64 | $ autoninja -C out/Default system_webview_apk |
| 65 | ``` |
| 66 | |
| 67 | ## Install WebView and switch provider |
| 68 | |
| 69 | ```shell |
| 70 | # Install the APK |
| 71 | $ out/Default/bin/system_webview_apk install |
| 72 | |
Nate Fischer | 8810efd | 2019-04-04 22:04:54 | [diff] [blame] | 73 | # Tell Android platform to load a WebView implementation from this APK |
| 74 | $ out/Default/bin/system_webview_apk set-webview-provider |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 75 | ``` |
| 76 | |
| 77 | ## Start running an app |
| 78 | |
| 79 | **That it!** Your APK should be installed and should be providing the WebView |
| 80 | implementation for all apps on the system. If you want to verify this, look at |
| 81 | the steps for [building the System WebView Shell](./webview-shell.md). The |
| 82 | version number in the shell's top bar should match the version number in your |
| 83 | local copy of `//chrome/VERSION`. |
| 84 | |
| 85 | ## Troubleshooting |
| 86 | |
| 87 | If the install command succeeded but something else is wrong, the best way to |
| 88 | troubleshoot the problem is to query the state of the on-device |
| 89 | WebViewUpdateService: |
| 90 | |
| 91 | ```shell |
Nate Fischer | fa3b0e04 | 2019-04-10 00:30:26 | [diff] [blame] | 92 | # If you don't have `adb` in your path, you can source this file to use |
| 93 | # the copy from chromium's Android SDK |
| 94 | $ source build/android/envsetup.sh |
| 95 | |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 96 | # Only available on O+ |
| 97 | $ adb shell dumpsys webviewupdate |
| 98 | |
| 99 | Current WebView Update Service state |
| 100 | Fallback logic enabled: true |
| 101 | Current WebView package (name, version): (com.google.android.apps.chrome, 75.0.3741.0) |
| 102 | Minimum WebView version code: 303012512 |
| 103 | Number of relros started: 1 |
| 104 | Number of relros finished: 1 |
| 105 | WebView package dirty: false |
| 106 | Any WebView package installed: true |
| 107 | Preferred WebView package (name, version): (com.google.android.apps.chrome, 75.0.3741.0) |
| 108 | WebView packages: |
| 109 | Valid package com.android.chrome (versionName: 58.0.3029.125, versionCode: 303012512, targetSdkVersion: 26) is installed/enabled for all users |
| 110 | Valid package com.google.android.webview (versionName: 58.0.3029.125, versionCode: 303012500, targetSdkVersion: 26) is NOT installed/enabled for all users |
| 111 | Invalid package com.chrome.beta (versionName: 74.0.3729.23, versionCode: 372902311, targetSdkVersion: 28), reason: No WebView-library manifest flag |
| 112 | Invalid package com.chrome.dev (versionName: 54.0.2840.98, versionCode: 284009811, targetSdkVersion: 24), reason: SDK version too low |
| 113 | Invalid package com.chrome.canary (versionName: 75.0.3741.0, versionCode: 374100010, targetSdkVersion: 25), reason: SDK version too low |
| 114 | Valid package com.google.android.apps.chrome (versionName: 75.0.3741.0, versionCode: 2, targetSdkVersion: 28) is installed/enabled for all users |
| 115 | ``` |
| 116 | |
| 117 | ### Invalid package ... No WebView-library manifest flag |
| 118 | |
| 119 | This APK does not contain a WebView implementation. Make sure you're building |
| 120 | `system_webview_apk`. |
| 121 | |
| 122 | ### Invalid package ... Version code too low |
| 123 | |
| 124 | This shouldn't happen for userdebug builds. If it does, add this GN arg: |
| 125 | |
| 126 | ```gn |
| 127 | # Any number >= "Minimum WebView version code": |
| 128 | android_override_version_code = "987654321" |
| 129 | ``` |
| 130 | |
| 131 | ### Invalid package ... SDK version too low |
| 132 | |
| 133 | The targetSdkVersion of your APK is too low (it must be >= the platform's API |
| 134 | level). This shouldn't happen for local builds using tip-of-tree chromium on |
| 135 | public OS versions (see [note](#Building-for-preview-Android-releases)). |
| 136 | |
| 137 | *** note |
| 138 | **Note:** we only support local development using the latest revision of the |
Nate Fischer | 8924a23f | 2021-05-04 00:05:25 | [diff] [blame] | 139 | main branch. Checking out release branches introduces a lot of complexity, and |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 140 | it might not even be possible to build WebView for your device. |
| 141 | *** |
| 142 | |
Nate Fischer | 78a27c0 | 2019-04-23 19:48:01 | [diff] [blame] | 143 | ### Invalid package ... Incorrect signature |
| 144 | |
| 145 | This shouldn't happen for userdebug devices, and there's no workaround for user |
| 146 | devices. Make sure you have a userdebug device (you can check with `adb shell |
| 147 | getprop ro.build.type`). |
| 148 | |
| 149 | ### Valid package ... **is** installed/enabled for all users |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 150 | |
| 151 | This is the correct state. If this is not the "preferred WebView package" or the |
| 152 | "current WebView package", call `set-webview-implementation` again. |
| 153 | |
Nate Fischer | 78a27c0 | 2019-04-23 19:48:01 | [diff] [blame] | 154 | ### Valid package ... **is NOT** installed/enabled for all users |
| 155 | |
| 156 | This shouldn't happen for `com.google.android.apps.chrome` (the recommended |
| 157 | package name). If you need to use a different package name, you may be able to |
| 158 | workaround this by enabling "redundant packages" (`adb shell cmd webviewupdate |
| 159 | enable-redundant-packages`), reinstalling, and running `set-webview-provider` |
| 160 | again. |
| 161 | |
| 162 | Otherwise, please [reach out to the team][1]. |
| 163 | |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 164 | ### My package isn't in the list |
| 165 | |
Nate Fischer | 9df47c7 | 2020-07-01 20:57:33 | [diff] [blame] | 166 | Either your package didn't install (see below) or you chose a package name which |
| 167 | is [not eligible as a WebView provider](webview-providers.md#Package-name) for |
| 168 | this device. Double-check the package name in your GN args. If you're on AOSP |
| 169 | (any OS level), choose `"com.android.webview"`. If you're on L-M, choose |
Chris Mumford | 94fe5edd | 2019-07-02 19:07:54 | [diff] [blame] | 170 | `"com.google.android.webview"`. In either case, you'll likely need to [remove |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 171 | the preinstalled WebView |
| 172 | APK](/android_webview/tools/remove_preinstalled_webview.py). |
| 173 | |
| 174 | ### WebView shell doesn't show the correct version |
| 175 | |
| 176 | Check the "Current WebView package" in the dumpsys output. You're probably |
| 177 | hitting one of the cases above. |
| 178 | |
Nate Fischer | 1dbe66d | 2019-06-25 20:56:54 | [diff] [blame] | 179 | ### INSTALL\_FAILED\_UPDATE\_INCOMPATIBLE: Package ... signatures do not match previously installed version |
| 180 | |
| 181 | This is probably because you've already installed Chrome Debug (ex. with the |
| 182 | Google-only `monochrome_apk` target, or through a Google-only official build). |
| 183 | This guide borrows that app's package name, but the locally compiled APK may not |
| 184 | have the same signing key, causing the `adb install` error. You should remove |
| 185 | the conflicting package with `out/Default/bin/system_webview_apk uninstall`, and |
| 186 | then try installing WebView again. |
| 187 | |
Nate Fischer | 78a27c0 | 2019-04-23 19:48:01 | [diff] [blame] | 188 | ### I couldn't install the APK/... is NOT installed. |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 189 | |
| 190 | This could fail for an even wider variety of reasons than already listed. Please |
Nate Fischer | 78a27c0 | 2019-04-23 19:48:01 | [diff] [blame] | 191 | [reach out to the team][1]. |
Nate Fischer | 59c2da76 | 2019-03-25 16:46:13 | [diff] [blame] | 192 | |
| 193 | ### I couldn't **build** the APK |
| 194 | |
| 195 | Try building Chromium. If that doesn't work, please reach out to [the chromium |
| 196 | team](https://groups.google.com/a/chromium.org/forum/#!forum/chromium-dev) for |
| 197 | general guidance. If `system_webview_apk` is the only troublesome target, please |
| 198 | reach out to the WebView team (see previous section). |
| 199 | |
| 200 | ## What if I didn't follow these instructions exactly? |
| 201 | |
| 202 | **Proceed at your own risk.** Building and installing WebView is, for a variety |
| 203 | of reasons, complex. If you've deviated from **any** of these instructions (and |
| 204 | don't know what you're doing) there's a good chance of making mistakes (some of |
| 205 | which don't have any error messages). |
| 206 | |
| 207 | If you can't follow the quick start guide for some reason, please consult our |
Nate Fischer | fdd8ca15 | 2019-06-12 03:24:38 | [diff] [blame] | 208 | [general build instructions](build-instructions.md). |
Nate Fischer | 78a27c0 | 2019-04-23 19:48:01 | [diff] [blame] | 209 | |
| 210 | [1]: https://groups.google.com/a/chromium.org/forum/#!forum/android-webview-dev |