Android O Webview source code download and compilation

After the release of Android O last year, according to the usual practice, I need to do some porting work, and combine the Pacth for our company's platform added in the previous version. Starting from Android M, the Chromium source code needs to be downloaded and compiled separately, and is no longer included in Android. Inside the source code. Generally, after downloading the Android source code, there will be a README file under the path oreo-mstar-master/external/chromium-webview. The content is as follows: It roughly explains some compilation parameters and the tag version used, here is the tag 58.0 .3029.125.

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 58.0.3029.125, using the GN build tool. To match our build settings, set:

target_os="android"
is_debug=false
is_official_build=true
is_chrome_branded=false
use_official_google_api_keys=false
exclude_unwind_tables=true
enable_resource_whitelist_generation=true
ffmpeg_branding="Chrome"
proprietary_codecs=true
enable_remoting=true
in your GN argument file before building.
------
Due to WebView API changes in the O release, the Java code in the Chromium 
3029_108 branch is not compatible with O. We'll be working on upstreaming 
the O-specific Java changes to Chromium once the final O SDK is released.
------
For questions about building WebView, please see

https://groups.google.com/a/chromium.org/forum/#!forum/android-webview-dev

The native webview.apk is located under oreo-mstar-master/external/chromium-webview/prebuilt/. There are several CPU types in this directory: arm, arm64, mips, x86, x86_64, the platform I use is arm64 bit , when we use the Chromium we downloaded to compile the webview.apk, we can overwrite it to the corresponding directory, or install it directly on the platform for verification.

After burning the Android O image on the development board, start the built-in browser, and you can also see the Chromium version used from the log, similar to the following log:

cr_LibraryLoader: Expected native library version number "58.0.3029.125", actual native library version number "58.0.3029.125"

So the first step is to download the Chromium  source code ( official tutorial ). Here I mainly list the complete steps and briefly explain them. If you want to see the official tutorial, you can click the previous link.

1. Get depot_tools: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

2. Add depot_tools to the environment variable: export PATH=$PATH:/path/to/depot_tools

3、下载Chromium source code:

~$mkdir oreo_chromium
~$cd oreo_chromium
~/ oreo_chromium $ fetch --nohooks android (Chromium checkout for Android platform)
~/ oreo_chromium $ gclient sync --with_branch_heads -r 58.0.3029.125 (cut to Android O tag)
~/ oreo_chromium $ cd src
~/ oreo_chromium / src# ./build/install-build-deps-android.sh (root permission, install Android-related compilation dependencies)

~/ oreo_chromium / src$  gclient runhooks (download some files needed for compilation)

The download process will take a long time, the whole package of code is about 30G, and the compiled code is about 40G. There are two main types of Chromium compilation tools: GPY and GN. Now it is recommended to use GN compilation. Only the compilation process of GN is introduced here:

1. Create a compilation directory: gn gen out/Release_arm64

2. Set the compilation parameters: gn args out/Release_arm64

Executing this step will directly enter vi, copy the parameters of the previous README, and then add a target_cpu="arm64" to specify the CPU type, as shown below:

target_os="android"
target_cpu="arm64"
is_debug=false
is_official_build=true
is_chrome_branded=false
use_official_google_api_keys=false
exclude_unwind_tables=true
enable_resource_whitelist_generation=true
ffmpeg_branding="Chrome"
proprietary_codecs=true
enable_remoting=true

3、编译webview.apk:ninja -C out/Release_arm64 system_webview_apk

The compilation process also takes a long time, depending on the performance of the server, it usually takes three or four hours.

After compiling, a SystemWebView.apk will be generated in the oreo_chromium/src/out/Release_arm64/apks directory, which can be directly installed on the board for testing. Before installation, you need to uninstall the webview that comes with the system, use pm uninstall com.android.webview It cannot be uninstalled, you need to go to the directory /system/app/webview on the board, delete or rename the original webview.apk, and then restart the board, it will be uninstalled automatically, and then install again: pm install -r / mnt/usb/190C-3332/o/SystemWebView.apk, after the installation was successful, it was found that the browser directly flashed back and the following log was printed:

WebViewFactory: Chromium WebView package does not exist
WebViewFactory: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
WebViewFactory:        at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:334)
WebViewFactory:        at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:398)

The previous installation is determined to have been successfully installed, but it still prompts No WebView installed. From this exception, the webview is not found. Check the relevant code, WebViewFactory.java, and find that there is a definition:

private static final String CHROMIUM_WEBVIEW_FACTORY =

            "com.android.webview.chromium.WebViewChromiumFactoryProviderForO";

Check the downloaded Chromium code, but found that there is no such class. In the directory oreo_chromium/src/third_party/android_tools/sdk, you can see that the dependent frameworks and sdk versions are Android N, which means that the downloaded Chromium package has The problem, the first idea after analyzing here is to compare the git log of Chromium Source and combine the code related to Android O. Here is another tool to recommend. You can view the source code of chromium online , but I found these in the process of combining the code. There are too many dependencies between commits. After completing a build fail, in order to solve the build fail, it is found that a new commit needs to be combined. Some commits are even made on the day, and they are repeatedly reverted and relanded. It seems that Google has not fully integrated. Okay.

Looking at the previous sync code record, I found that there was also an error in the log, but it did not affect the compilation. With these questions, I posted a post to the Chromium forum for help, and I usually got a reply the next day.

[0:03:45] fatal: unable to access 'https://chromium.googlesource.comnative_client/pnacl-subzero/': Could not resolve host: chromium.googlesource.comnative_client

Chromium's reply is as follows, to be compatible with Android O, tag 62.0.3200.0 is required, and it is not yet a stable version. . . This statement is actually very strange. The version released by Android O has its own webview tag 58.0.3029.125, and the Google SRI project also uses this version, so I don't understand them. .


After waiting for more than a month, I finally waited for a stable version compatible with Android O. Here is also a link to check the version release . In the end, the version I used was 62.0.3202.73, which was compiled and put on the board to run and everything was normal.






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324849669&siteId=291194637
Recommended