简体   繁体   English

从 Chromium 为 Android 构建 WebView

[英]Building WebView From Chromium for Android

I am trying to follow the instructions to build the webview apk from chromium base.我正在尝试按照说明从铬基构建 webview apk。 I am running a Android-7.0 build.我正在运行 Android-7.0 构建。 I finished the compilation process for chromium and generated the APK.我完成了 Chromium 的编译过程并生成了 APK。 I have two questions related to steps after APK generation.我有两个与 APK 生成后步骤相关的问题。

Firstly the library name is different from what I expected.首先,库名称与我的预期不同。 The default webview.apk has a library name libwebviewchromium.so , but the APK I built from chromium ( SystemWebView.apk ) contains the lib libwebviewchromium.cr.so .默认的webview.apk有一个库名称libwebviewchromium.so ,但我从 chromium ( SystemWebView.apk ) 构建的 APK 包含libwebviewchromium.cr.so I wanted to ask whether that can cause problems and if others also saw this.我想问这是否会导致问题,以及其他人是否也看到了这一点。

Secondly, I am unable to uninstall the com.android.webview app from the device.其次,我无法从设备上卸载com.android.webview应用程序。 The instructions require uninstallation of this app and deleting its folder before the new APK can be installed.说明要求卸载此应用并删除其文件夹,然后才能安装新的 APK。 I get the error:我得到错误:

$ adb uninstall com.android.webview     
[DELETE_FAILED_INTERNAL_ERROR]

I wanted to ask if anyone knows how to resolve this.我想问是否有人知道如何解决这个问题。 I saw a related question and want to ask if there is any other approach that doing what this answer suggests.我看到了一个相关的问题,并想问是否有任何其他方法可以按照这个答案的建议进行操作。

The following answer is related to the second part of my question.以下答案与我的问题的第二部分有关。

I did the following steps to make the SystemWebView.apk work (note: the webview.apk was a system app in my build under /system/app ; the steps below were used to install & test SystemWebView.apk as a third party app)我执行了以下步骤以使SystemWebView.apk工作(注意: webview.apk是我在/system/app下构建的系统应用程序;以下步骤用于安装和测试SystemWebView.apk作为第三方应用程序)

(Take a look at step 6 first for taking back up of 2 files) (先看第 6 步,备份 2 个文件)

  1. Firstly I followed the linked answer to adb pull & edit the packages.xml and packages.list files (I haven't pushed them yet)首先,我按照 adb pull 的链接答案编辑packages.xmlpackages.list文件(我还没有推送它们)
  2. adb shell stop adb 外壳停止
  3. I push the two files我推送这两个文件
  4. I then deleted the following folders (basically any trace of com.android.webview ):然后我删除了以下文件夹(基本上是com.android.webview的任何痕迹):
 /system/app/webview /data/data/com.android.webview /data/user/0/com.android.webview /data/misc/profiles/cur/0/com.android.webview /data/misc/profiles/ref/com.android.webview /data/user_de/0/com.android.webview
  1. adb install SystemWebView.apk adb install SystemWebView.apk

  2. I also had kept a back up of libwebviewchromium64.relro and libwebviewchromium32.relro files from /data/misc/shared_relro/ .我还备份了/data/misc/shared_relro/中的libwebviewchromium64.relrolibwebviewchromium32.relro文件。 After the install, I noticed that these files get erased for some reason, so I copied them in again (first copying into sdcard and then moving into shared_relro folder).安装后,我注意到这些文件由于某种原因被删除了,所以我再次复制它们(首先复制到 sdcard 然后移动到shared_relro文件夹)。

  3. adb shell start adb 外壳启动

After that I tested a simple app containing a WebView , and could see web pages loaded.之后,我测试了一个包含WebView的简单应用程序,并且可以看到加载的网页。

You have to build SystemWebView.apk with ninja -C out/Release system_webview_apk您必须使用 ninja -C out/Release system_webview_apk 构建 SystemWebView.apk

For more details check this page.有关更多详细信息,请查看此页面。 https://chromium.googlesource.com/chromium/src/+/master/docs/android_build_instructions.md and https://www.chromium.org/developers/how-tos/build-instructions-android-webview https://chromium.googlesource.com/chromium/src/+/master/docs/android_build_instructions.mdhttps://www.chromium.org/developers/how-tos/build-instructions-android-webview

adb uninstall com.android.webview adb 卸载 com.android.webview

fails because this is a system app, you can directly replace the webview.apk in /system/app/webview/ dir, after this do stop && start for this you need root permission.失败,因为这是一个系统应用程序,您可以直接替换 /system/app/webview/ 目录中的 webview.apk,在此之后执行 stop && start 为此您需要 root 权限。

Native web view has many limitations in performance and caching.原生 Web 视图在性能和缓存方面有很多限制。
I would rather suggest you to CustomTabsClient , a web view supported by Chrome Browser.我宁愿建议您使用 Chrome 浏览器支持的 Web 视图CustomTabsClient
you could get it by adding following dependencies to your project.您可以通过在项目中添加以下依赖项来获得它。

dependencies {
...
compile 'com.android.support:customtabs:23.3.0'
}

For more detail visit.更多详情请访问。
https://developer.chrome.com/multidevice/android/customtabs https://developer.chrome.com/multidevice/android/customtabs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM