15

Android 5.0.0 running in emulator appears to not take Web View updates. That is, Android System Webview installs just fine from the Play Store (link). However, the browser continues to use the older stock WebView (according to the user-agent string).

Why isn't webview upgrading in the emulator and how can it be done?


P.S. The upgrade appears installed alongside the stock WebView (both show up in the list of applications). Tried installing via Play Store and manually to no avail.

P.P.S. The purpose of this is to test how my code handles a particular bug in a certain version of webview.

djslavik
  • 151
  • 1
  • 5

3 Answers3

5

5 year old question, and yet I found it yesterday and got to solve it after some tinkering.

First, as to why installing the webview from the play store doesn't work, that is answered in this question. In a nutshell, the emulator is using com.android.webview whilst google play installs com.google.android.webview. And there is no way (that I know of) to configure the emulator to use Google's webview. So using the play store is a dead end.

What I could achieve though is uninstall the default webview and install a newer version. I wasn't able to just upgrade it because the apk I got for the new webview had a different signature from the one installed. But uninstalling isn't straightforward either, because the webview is a system app and you won't be able to uninstall it running adb uninstall.

Here's what I did:

# Boot the emulator in write mode and make /system writable
emulator @DeviceName -writable-system
adb remount

# Uninstall the webview app manually and reboot the device
adb shell
rm -rf /data/data/com.android.webview
rm -rf /system/app/webview
reboot

# Install the new version
adb install webview.apk

One drawback of this approach is that you'll need to boot your device in write mode for subsequent runs (no need to run adb remount again though). But it works!

In case you're wondering, I got the apk for the new version from Google's source (no need to compile manually).

Noel De Martin
  • 2,779
  • 4
  • 28
  • 39
  • You can switch if you have the developer options. Settings > Developer Options > WebView implementation – Bobby Morelli Sep 19 '22 at 17:12
  • @BobbyMorelli I can't, it's stuck on one option and you can't change it for any other. – gaborous Feb 04 '23 at 19:01
  • Note you might need to also execute these shell commands: `rm -rf /system/app/WebViewGoogle` `rm -rf /data/data/com.android.webview` – josemmo Apr 09 '23 at 10:23
2

This answer simply expands on Noel De Martin one, as i encountered several troubles getting the apk version and actually installing it.

First, as to why installing the webview from the play store doesn't work, that is answered in this question. In a nutshell, the emulator is using com.android.webview while google play installs com.google.android.webview. And there is no way (that I know of) to configure the emulator to use Google's webview. So using the play store is a dead end.

What I could achieve though is uninstall the default webview and install a newer version. I wasn't able to just upgrade it because the apk I got for the new webview had a different signature from the one installed. But uninstalling isn't straightforward either, because the webview is a system app and you won't be able to uninstall it running adb uninstall.

Here's what I did:

# Boot the emulator in write mode and make /system writable
emulator @DeviceName -writable-system 
adb remount

# Uninstall the webview app manually and reboot the device
adb shell
rm -rf /data/data/com.android.webview
rm -rf /system/app/webview
reboot

# Install the new version
adb install webview.apk

In case you get an "emulator not found" error on the first step, you probably need to add various android variable to your path, I used an inspiration from this question (my path were different as I am on wsl, and I added the soruce command in my .bashrc file)

One drawback of this approach is that you'll need to boot your device in write mode for subsequent runs (no need to run adb remount again though). But it works!

In case you're wondering, I got the apk for the new version from Google's source (no need to compile manually).

To download an apk from google source, I had to find the proper apk I needed, on https://android.googlesource.com/platform/external/chromium-webview/+log, searching in the commit messages for my version.

After that, I needed to find my emulator version, for which https://stackoverflow.com/a/33370234/7059810 gave me the answer.

Finally, to actually download the apk, I needed to use the tgz link on a folder from google git (as shown on this screenshot : a screenshot of the previous link, the tgz link colored in purple). Indeed, I found no other way to download the apk.

Hope it helps someone.

Jonathan Simonney
  • 585
  • 1
  • 11
  • 25
  • Note that both `%AppData\Android\Sdk\emulator` for `emulator` binary (not the `tools` folder as suggested in the link otherwise you'll get a [PANIC error](https://stackoverflow.com/a/52496987/1121352)) and `%AppData\Android\Sdk\platform-tools` for `adb` binary need to be in the `PATH`. Also the first emulator command did not work, I had to first type `emulator -list-avds` to get the list of AVD images, then `emulator -avd Image_Name -writable-system` instead of `@Image_Name`, the latter didn't work on Win 10. To get the tgz file on Google Git, go to parent folder. – gaborous Feb 04 '23 at 19:30
  • Also to be able to make it a writeable system, you need to install a non-google-play image, otherwise a user build of `adb` will be installed instead of an engineer build, so that you won't be able to access root commands. See [this answer](https://stackoverflow.com/a/67796246/1121352). And the AVD image must be turned off before typing `emulator -avd Image_Name -writable-system`, because this command will launch the image with write permissions, else it'll complain it can't work on multiple parallel images at once. Then open a 2nd terminal, type `adb root`, then `adb remount`, then the rest. – gaborous Feb 04 '23 at 19:35
1

Since Android 4.4, WebView uses Chrome to render. So you can update Chrome instead of WebView.

In particular, I tried all the other approaches to update the WebView in an emulated AVD image, such as trying to install an upgraded Chrome or WebView via an APK, even an AOSP build, will result in crashes and bugs.

The only way I found to work in Android Studio's AVD emulator is to simply update Chome using the Play Store inside a Play Store enabled AVD image. Then, you can launch the WebView Browser Tester app, and it should show in the title bar the updated Chrome version number. Tested on Android Studio 2022.1 on Windows 10.

gaborous
  • 15,832
  • 10
  • 83
  • 102