1. 程式人生 > >android 6.0 以後 WebView改動

android 6.0 以後 WebView改動

android 6.0

Building the Chromium-based WebView in AOSP is no longer supported. WebView can
now be built entirely from the Chromium source code.


General instructions for building WebView from Chromium:
https://www.chromium.org/developers/how-tos/build-instructions-android-webview


------


The prebuilt libwebviewchromium.so included in these APKs is built from Chromium
release tag 44.0.2403.114. To match our build settings, set:


GYP_DEFINES="OS=android release_unwind_tables=0 buildtype=Official chrome_build_id='2e7c7a0f-c733-4b9a-9c8e-d3cf0938369b'"


in your environment before running build/gyp_chromium.


------
Due to WebView API changes in the M release, the Java code in the Chromium 2403
branch is not compatible with M. We'll be working on upstreaming the M-specific
Java changes to Chromium once the final M SDK is released.

在android 6.0 以後 針對typeface部分,可以考慮修改external/skia/src/ports/SkFontMgr_android.cpp

1、首先測試底層流程,通過新增Log 資訊:

通過定義巨集,引入android層log

#include <android/log.h>

#define LOG_TAG "TESTFONT"

#define ALOG(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)

使用上 和log.d,log.e,log.v,log.i,log.w基本一致

2、編譯ROM 裝機執行。。

3、通過adb logcat 檢視資訊

4、增加對.so檔案除錯的資訊。

對.so檔案除錯:使用arm-linux-androideabi-4.9 除錯log中的具體地址資訊。

由於命令過長,使用alias別名方式:

alias(中文稱為“別名”)允許使用更加簡短的名稱來重新定義 Linux 中的 Shell 命令,從而簡化命令列的輸入。如果經常與 CLI 打交道,那麼使用 alias 不僅會節省時間,而且也能提高效率,真是一舉兩得的好事。
基本用法: alias 的基本使用方法為:alias 新的命令='原命令 -選項/引數'。舉例說明,alias l=‘ls -lsh' 將重新定義 ls 命令,現在只需輸入 l 就可以列目錄了。
獲知別名: 直接輸入 alias 命令會列出當前系統中所有已經定義的命令別名。
刪除別名: 要刪除一個別名,可以使用 unalias 命令,如 unalias l。
這個方法只是暫時的,如果重啟一次就失效了,永久生效一個命令怎麼辦呢?
開啟 .bashrc (應該是ubuntu發行版的,其他發行版也許可以修改.bash_profile)可以看到
……
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
……
方法1 :直接在我們的 環境變數檔案中新增 alias xx='xxxxx'
方法2  : .bashrc 中有一句話
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
就是說可以另外新建一個檔案用於專門存放自己的alias資訊

  $ cd
  $ vi .bash_aliases
  在檔案中輸入自己想設定的命令  alias rm='rm -i'  然後儲存推出
  $ source .bash_aliases   #讓我們的環境生效

總之,要關注你所改動原始碼中的提示資訊,一般都會很用。

5、使用.so檔案除錯,具體定位到程式碼crash的具體行數,進行下一步分析。

6    替換libskia.so以後,webview字型沒有改變,方法失敗。嘗試分析webviewgoogle.apk。在android6.0 以後,由於都是webview發生改動,渲染工作均由google自己提供的apk提供,對vendor/google/apps/WebViewGoogle.apk進行分析,使用aapt工具,我們發現其使用了一個libwebviewchromium.so動態連結庫,使用readelf對其進行解析

部分關鍵程式碼如下:

Dynamic section at offset 0x1c9ee8c contains 28 entries:
  標記        型別                         名稱/值
 0x00000003 (PLTGOT)                     0x1ca6ab8
 0x00000002 (PLTRELSZ)                   2680 (bytes)
 0x00000017 (JMPREL)                     0x1f4180
 0x00000014 (PLTREL)                     REL
 0x00000011 (REL)                        0x1eb90
 0x00000012 (RELSZ)                      1922544 (bytes)
 0x00000013 (RELENT)                     8 (bytes)
 0x6ffffffa (RELCOUNT)                   240244
 0x00000006 (SYMTAB)                     0x18c
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000005 (STRTAB)                     0x59dc
 0x0000000a (STRSZ)                      93051 (bytes)
 0x00000004 (HASH)                       0x1c558
 0x00000001 (NEEDED)                     共享庫:[liblog.so]
 0x00000001 (NEEDED)                     共享庫:[libandroid.so]
 0x00000001 (NEEDED)                     共享庫:[libjnigraphics.so]
 0x00000001 (NEEDED)                     共享庫:[libm.so]
 0x00000001 (NEEDED)                     共享庫:[libc.so]
 0x00000001 (NEEDED)                     共享庫:[libdl.so]
 0x0000000e (SONAME)                     Library soname: [libwebviewchromium.so]
 0x0000001a (FINI_ARRAY)                 0x1bdd8d8
 0x0000001c (FINI_ARRAYSZ)               8 (bytes)
 0x00000019 (INIT_ARRAY)                 0x1c9fe68
 0x0000001b (INIT_ARRAYSZ)               36 (bytes)
 0x00000010 (SYMBOLIC)                   0x0
 0x0000001e (FLAGS)                      SYMBOLIC BIND_NOW
 0x6ffffffb (FLAGS_1)                    標誌: NOW
 0x00000000 (NULL)                       0x0


重定位節 '.rel.dyn' 位於偏移量 0x1eb90 含有 240318 個條目:
 Offset     Info    Type            Sym.Value  Sym. Name
01b61cc8  00000017 R_ARM_RELATIVE
這其中只有一部分共享庫,其他的渲染部分由其自己提供,所以基本上沒有辦法在android 6.0 以後對webview做出更多改動。