18

I downloaded and installed the latest version of android system WebView from the app store on my android tablet (running 5.0.2).

But apps still go on using the old webview version (39.0.0.0).

How can I get them to switch ?

For info, I've tried disabling the old one, and it get re-enabled when I open an app that uses webview.

5
  • 2
    Out of curiosity, how do you know which version of Webview an app is using? Mar 11 '16 at 21:29
  • 1
    I have been testing with several apps, such as Droidscript and WebView Browser and visited whatsmyuseragent Mar 11 '16 at 21:34
  • I've read through the Lollipop source, and this shouldn't be happening. It should use the latest unless the manufacturer has replaced the WebViewFactory class with their own. What exact device/model and manufacturer-supplied version are you running?
    – Mufasa
    Mar 21 '16 at 3:56
  • Hi Musafa why did you delete your answer? Mar 21 '16 at 14:56
  • I'm using low-cost tablets, and I tried on several brands (digiflip from flipkart, time2), I'm going to try on the lenovo TAB 2 A7 in the coming days Mar 21 '16 at 14:58
20

You can't change this without root.

The system framework is hard-coded to use a specific package for applications that request a WebView component. By default (in AOSP) it uses the value com.android.webview, which is the version that is compiled during the AOSP build process. On devices from manufacturers that modify this component, the package name may differ. Regardless, in order to replace the WebView that shipped with your device, you have to modify this value to instead be com.google.android.webview.

The "by hand" way of doing this would be to pull the framework-res.apk file from your device, de-compile it, and change the value of the config_webViewPackageName resource variable. It should be located at /res/values/strings.xml within the .apk. Once you've done this, you would need to re-package everything and push the new .apk to your device, replacing the old one.

An alternative method that you can attempt is to install the Xposed framework and then use the WebViewGoogle module. If you use a custom ROM, you may also be able to find a package that will permanently modify the necessary framework components (or it may be built to use Google's WebView by default).

My hypothesis would be that this restriction exists in part because the system relies on a WebView implementation existing in some form, so if it could be modified by a user it could break the system in odd ways. There would also be security implications to allowing apps to override the system WebView, such as a bad-actor attempting to provide a malicious one without the user knowing.

As a point of further explanation: the reason the System WebView is available in the Play Store to begin with is that Nexus devices (and possibly others) ship with it pre-installed, and configured to use it. It is, in effect, the system WebView for those devices.Thus, Google is able to provide WebView updates for these devices via the Play Store so that full system OTAs are not necessary just to update the browser/WebView. There are other components that Google has migrated to Play Store updating in a similar fashion, with the reasoning essentially being that it is faster. Phone and Contacts were two of the more recent ones, with the linked article providing some additional detail regarding why Google has taken this approach.

10
  • 1
    Thanks for this explaination.. but, what is the use of this android system webview app then? Mar 11 '16 at 21:46
  • 1
    @Clémentine Nexus devices (possibly others) ship with it pre-installed, and configured to use it. It is, in effect, the system WebView for those devices.Thus, Google is able to provide WebView updates for these devices via the Play Store so that full system OTAs are not necessary just to update the browser/WebView. There are other components that Google has migrated to Play Store updating in a similar fashion, with the reasoning essentially being that it is faster. Mar 11 '16 at 21:48
  • 1
    why are all tablets running lollipop or newer OS not using this as their default system WebView, sounds like a waste! Mar 11 '16 at 21:54
  • 1
    @Clémentine Google's control over third-party manufacturers is somewhat limited. They probably could opt to use Google's closed-source WebView just as Nexus devices do, but they may choose not to for whatever reason. I'm not sure of the specifics regarding how Google licenses their closed-source applications to OEMs, but those terms (whatever they may be) could be a factor in the manufacturer's decision. Mar 11 '16 at 21:59
  • Thanks for all this info. Shedding light on a lot of questions I had at the back of my mind. Will be looking for a tablet that has it pre-installed then. Mar 11 '16 at 22:15
3

I have followed @eldarerathis's answer and made a step by step guide on how to update webview on an Android 5.0 emulator. It probably works on Android 5.1 to Android 6.0 as well. Hope it will help anyone who wish to use a more recent webview on old Android devices.

https://gist.github.com/ppoffice/9ce9790708eeabbec1281467e25139e4

Tools

  1. emulator (30.3.5) (via Android SDK)
  2. adb (30.0.5) (via Android SDK)
  3. apktool (2.5.0) and Java runtime
  4. zip (3.0)
  5. unzip (6.0)

Make sure you have JAVA_HOME and ANDROID_HOME environment variables correctly set.

Steps

  1. Create a new Android Virtual Device (AVD) using Android Studio or avdmanager. Here, I created an Android 5.0 device with the following system image:

    Path                                        | Version | Description                                | Location
    system-images;android-21;google_apis;x86_64 | 32      | Google APIs Intel x86 Atom_64 System Image | system-images/android-21/google_apis/x86_64/
    

    The AVD name is

    $ emulator -list-avds
    Pixel_2_API_21
    
  2. Boot the AVD and make its system partition writable:

    $ $ANDROID_HOME/tools/emulator @Pixel_2_API_21 -writable-system
    

    And the AVD starts, remount its system partition using adb:

    $ $ANDROID_HOME/platform-tools/adb remount
    
  3. Download the Android System Webview of your desired version from the internet. For example, you may use Android System WebView 88.0.4324.93 (x86 + x86_64) (Android 5.0+) from apkmirror.com. The package ID is com.google.android.webview, which is different from the default system webview (com.android.webview). Also, make sure your package has the same ABI as your AVD.

  4. Extract the webview package using unzip and push it and the native libraries to the system partition of your AVD:

    $ unzip <path/to/your/webview.apk>
    $ $ANDROID_HOME/platform-tools/adb shell mkdir /system/app/ChromiumWebview
    $ $ANDROID_HOME/platform-tools/adb push <path/to/your/webview.apk> /system/app/ChromiumWebview/webview.apk
    $ $ANDROID_HOME/platform-tools/adb push <path/to/your/extracted/webview.apk>/lib /system/app/ChromiumWebview/
    

    After this step is done, you should have the following new files in your AVD:

    $ANDROID_HOME/platform-tools/adb shell ls -lR /system/app/ChromiumWebview/lib                                                            ✔ 
    
    /system/app/ChromiumWebview/lib:
    drwxr-xr-x root     root              2021-01-27 00:36 x86
    drwxr-xr-x root     root              2021-01-27 00:36 x86_64
    
    /system/app/ChromiumWebview/lib/x86:
    -rw-r--r-- root     root        43360 1979-12-31 00:00 libchromium_android_linker.so
    -rw-r--r-- root     root         3680 1979-12-31 00:00 libcrashpad_handler_trampoline.so
    -rw-r--r-- root     root     78167008 1979-12-31 00:00 libwebviewchromium.so
    
    /system/app/ChromiumWebview/lib/x86_64:
    -rw-r--r-- root     root        44896 1979-12-31 00:00 libchromium_android_linker.so
    -rw-r--r-- root     root         5104 1979-12-31 00:00 libcrashpad_handler_trampoline.so
    -rw-r--r-- root     root     78545528 1979-12-31 00:00 libwebviewchromium.so
    
  5. Restart Android services to let the Package Manager pick up our new webview package:

    $ $ANDROID_HOME/platform-tools/adb shell stop
    $ $ANDROID_HOME/platform-tools/adb shell start
    $ $ANDROID_HOME/platform-tools/adb shell pm list packages | grep webview
    package:com.android.webview           --> the built-in and outdated webview
    package:com.google.android.webview    --> our new webview
    
  6. Check if the package is registered with the Package Manager. Make sure codePath, nativeLibraryPath, and primaryCpuAbi are correct:

    $ $ANDROID_HOME/platform-tools/adb shell cat /data/system/packages.xml | grep com.google.android.webview
    <package name="com.google.android.webview" codePath="/system/app/ChromiumWebview" nativeLibraryPath="/system/app/ChromiumWebview/lib" primaryCpuAbi="x86_64" secondaryCpuAbi="x86" flags="...
    
  7. As the default webview package name used by the Android OS is hard-coded in older Android OSes (https://android.stackexchange.com/a/139415), you need to modify the Android framework to use the new package name. First, pull framework-res.apk from your AVD and decompile it using apktool:

    $ $ANDROID_HOME/platform-tools/adb pull /system/framework/framework-res.apk
    $ apktool d framework-res.apk
    
  8. Update the <path/to/extracted/framework-res.apk>/res/values/strings.xml file to use your new system webview package name:

    --- res/values/strings.xml   2021-01-27 00:53:05.000000000 -0500
    +++ res/values/strings.xml   2021-01-27 00:54:38.000000000 -0500
    @@ -70,7 +70,7 @@
         <string name="config_appsAuthorizedForSharedAccounts">;com.android.settings;</string>
         <string name="config_defaultNetworkScorerPackageName" />
         <string name="config_persistentDataPackageName" />
    -    <string name="config_webViewPackageName">com.android.webview</string>
    +    <string name="config_webViewPackageName">com.google.android.webview</string>
         <item type="string" name="timepicker_circle_radius_multiplier">0.82</item>
         <item type="string" name="timepicker_circle_radius_multiplier_24HourMode">0.85</item>
         <item type="string" name="timepicker_selection_radius_multiplier">0.16</item>
    
  9. Repack framework-res.apk using apktool.

    $ apktool b <path/to/extracted/framework-res.apk>
    

    There might be a few errors you need to fix before the package can be repacked. For example, if you encountered the following error:

    Error: String types not allowed (at 'APKTOOL_DUMMY_34e' with value '').
    

    you should replace <drawable name="APKTOOL_DUMMY_..." /> with <item type="drawable" name="APKTOOL_DUMMY_..." /> in the <path/to/extracted/framework-res.apk>/res/values-nodpi-v4/drawables.xml file and retry.

  10. The repacked framework-res.apk is placed under <path/to/extracted/framework-res.apk>/dist. Extract the resources.arsc file from it and merge it to the original framework-res.apk:

    $ unzip <path/to/extracted/framework-res.apk>/dist/framework-res.apk resources.arsc -d .
    $ zip -0 <path/to/original/framework-res.apk> resources.arsc
    

    The original framework-res.apk you pulled from your AVD is now updated.

  11. Next, replace the framework-res.apk in your AVD with our updated (merged) framework-res.apk from last step and reboot device:

    $ $ANDROID_HOME/platform-tools/adb push <path/to/original/framework-res.apk> /system/framework/framework-res.apk
    $ $ANDROID_HOME/platform-tools/adb reboot
    
  12. Finally, check if the webview is switched to the new one:

1
  • Well this explains why is always easier to use the Store to update the Webview.. too bad emulator forbids usage of the Play Store.
    – andreszs
    Jun 29 at 13:40
0

Continuing the previous answer. For android 7 and up: pull the framework-res.apk file from your device, de-compile it, and change file /res/xml/config_webview_packages.xml, add to it a new webviewprovider.

Example config_webview_packages.xml:

<webviewproviders>
    <webviewprovider description="Android WebView" packageName="com.android.webview" availableByDefault="true" />
    <webviewprovider description="Google WebView" packageName="com.google.android.webview" availableByDefault="true">
        <signature>MIIDuzCCAqOgAwIBAgIJANi6DgBQG4ZTMA0GCSqGSIb3DQEBBQUAMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKDAtHb29nbGUgSW5jLjEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UEAwwHd2VidmlldzAeFw0xNDA4MDgyMzIwMjBaFw00MTEyMjQyMzIwMjBaMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKDAtHb29nbGUgSW5jLjEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UEAwwHd2VidmlldzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbtaFX0r5aZJMAbPVMAgK1ZZ29dTn91VsGxXv2hqrQo7IpqEy2JmPvPnoMsSiuTAe+UcQy8oKDQ2aYVSAd1DGIy+nSRyFTt3LSIAdwSBkB1qT4a+OqkpsR6bSNXQXQ18lCQu9gREY3h3QlYBQAyzRxw4hRGlrXAzuSz1Ec4W+6x4nLG5DG61MAMR8ClF9XSqbmGB3kyZ70A0X9OPYYxiMWP1ExaYvpaVqjyZZcrPwr+vtW8oCuGBUtHpBUH3OoG+9s2YMcgLG7vCK9awKDqlPcJSpIAAj6uGs4gORmkqxZRMskLSTWbhP4p+3Ap8jYzTVB6Y1/DMVmYTWRMcPW0macCAwEAAaNQME4wHQYDVR0OBBYEFJ6bAR6/QVm4w9LRSGQiaR5Rhp3TMB8GA1UdIwQYMBaAFJ6bAR6/QVm4w9LRSGQiaR5Rhp3TMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAEQu8QiVxax7/diEiJrgKE1LwdXsIygJK/KnaKdnYEkAQpeu/QmrLiycm+OFbL1qHJIB7OuI/PQBUtcaNSiJSCVgtwtEbZWWIdsynqG/Nf4aGOndXegSQNRH54M05sRHLoeRycPrY7xQlEwGikNFR76+5UdwFBQI3Gn22g6puJnVukQm/wXQ+ajoiS4QclrNlixoDQsZ4STLH4+Wju2wIWKFFArIhVEIlbamq+p6BghuzH3aIz/Fy0YTQKi7SA+0fuNeCaqlSm5pYSt6p5CH89y1Fr+wFc5r3iLRnUwRcy08ESC7bZJnxV3d/YQ5valTxBbzku/dQbXVj/xg69H8l8M</signature>
    </webviewprovider>
</webviewproviders>

About signature. If webviewprovider.apk signed system signature then you can skip this attribute. If the signature is not correct, the webview provider will not appear in the list available through the device development settings. Don't change original signature of webviewProvider.apk - you won't be able to install updates.

Put framework-res.apk to device (need root).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.