WebViewGoogle和Chrome的踩坑总结

首先看一下谷歌的叙述

On Android 7.x where first api < 24, you should preinstall a regular APK of both Chrome and WebView, of the same version as each other.
On Android 7.x where first api >= 24, you should preinstall Chrome, and the WebView stub 0.0.0.1.
On Android 8.x and later, you should preinstall Chrome and the WebView stub of the same version as Chrome.

在GMS中WebViewGoogle和Chrome是比较特殊的一对App,更新的时候一不小心就可能造成CTS fail和GTS fail,影响比较大。

对于first api < 24 (一般是 android 7.0 ,7.1的机型 ),只要WebViewGoogle和Chrome的版本保持一致就行了。

对于 first api >= 24 ,有如下总结点:

  1. 国际版预置的是Chrome 和WebViewStub ,国内版没有Chrome,只预置WebViewGoogle
  2. 在android 7.1 上,WebViewStub的版本是0.0.0.1, android 8.x and later WebViewStub已经有自己的版本且要与Chrome的版本一致。

还有一点必须要注意(亲自踩过坑):

在Android 7.1上的机型,有的first api 是23,有的是25,然而我们vendor/google是共分支,所以更新的时候要注意:

  1. WebViewGoogle和Chrome都要更新且版本保持一致,以使用于first api是23的机型。
  2. WebViewStub 保持不变或者更新为一个版本为0.0.0.1的apk(现在比较难找到这样的apk),以适用于first api为25的机型。
    So,没什么必要,不要更新android 7.x and before 机型的Chrome和WebView。

查看机器的first api :adb shell getprop ro.product.first_api_level

在android 9.0 和 2018-10之后的android 8.x ,WebViewGoogle和WebViewStub定义成两个module,Chrome把WebViewStub当成依赖并覆盖WebViewGoogle。更简析明了。代码如下:

###############################################################################
# WebView Chromium
LOCAL_PATH := $(call my-dir)
 
my_archs := arm arm64 x86 x86_64
my_src_arch := $(call get-prebuilt-src-arch, $(my_archs))
 
include $(CLEAR_VARS)
LOCAL_MODULE := WebViewGoogle
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
#LOCAL_PRIVILEGED_MODULE :=
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_OVERRIDES_PACKAGES := webview
LOCAL_SRC_FILES := $(LOCAL_MODULE)_$(my_src_arch).apk
LOCAL_MULTILIB := both
LOCAL_REQUIRED_MODULES := \
    libwebviewchromium_loader \
    libwebviewchromium_plat_support
include $(BUILD_PREBUILT)
 
include $(CLEAR_VARS)
LOCAL_MODULE := WebViewStub
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
#LOCAL_PRIVILEGED_MODULE :=
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_OVERRIDES_PACKAGES := webview
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MULTILIB := both
LOCAL_REQUIRED_MODULES := \
    libwebviewchromium_loader \
    libwebviewchromium_plat_support
include $(BUILD_PREBUILT)

###############################################################################
# Chrome
LOCAL_PATH := $(call my-dir)
 
my_archs := arm arm64 x86 x86_64
my_src_arch := $(call get-prebuilt-src-arch, $(my_archs))
 
include $(CLEAR_VARS)
LOCAL_MODULE := Chrome
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
#LOCAL_PRIVILEGED_MODULE :=
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_OVERRIDES_PACKAGES := WebViewGoogle
LOCAL_SRC_FILES := $(LOCAL_MODULE)_$(my_src_arch).apk
LOCAL_REQUIRED_MODULES := WebViewStub BookmarkProvider PartnerBookmarksProvider
LOCAL_MODULE_TARGET_ARCH := $(my_src_arch)
-include $(MIUI_PREINSTALL_APP_MODULE_PATH_MK)
LOCAL_DEX_PREOPT := false
LOCAL_MULTILIB := both
include $(BUILD_PREBUILT)

你可能感兴趣的:(GMS)