How to upgrade Android's Webview in Emulator (Android 5)
Asked Answered
H

3

17

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.

Homecoming answered 3/5, 2015 at 22:8 Comment(1)
wow an really old question and yet I have the same one today :(Past
R
7

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).

Release answered 10/3, 2021 at 7:38 Comment(5)
You can switch if you have the developer options. Settings > Developer Options > WebView implementationMexicali
@BobbyMorelli I can't, it's stuck on one option and you can't change it for any other.Malformation
Note you might need to also execute these shell commands: rm -rf /system/app/WebViewGoogle rm -rf /data/data/com.android.webviewCurhan
I was using a Pixel 7 API 30 with Android 11.0 ("R") | x86. My system came with "Android System WebView 83.x" pre-installed. Then I went to the Play Store and installed "Android System WebView Dev 127.x". Then I was able to switch between WebView versions from Settings like @BobbyMorelli described.Gothart
This question is about Android 5, so those developer options may not be available there.Release
M
3

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://mcmap.net/q/209931/-how-to-find-arm-processor-version-on-android-device 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.

Mcgovern answered 29/8, 2022 at 14:59 Comment(2)
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) 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.Malformation
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. 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.Malformation
M
3

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.

Malformation answered 4/2, 2023 at 20:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.