0

Update Android docs for which APKs exist & native library nuances

Change-Id: Ic28a211303da84db90c30cab032e920a419537bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2280143
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Peter Wen <wnwen@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/master@{#785526}
This commit is contained in:
Andrew Grieve
2020-07-06 20:31:50 +00:00
committed by Commit Bot
parent ed8939801a
commit 84bf1dda1d
2 changed files with 42 additions and 24 deletions

@ -184,29 +184,27 @@ depending on the version of Android running on a device. Chrome uses this
feature to target 4 different versions using 4 different ninja targets:
1. `chrome_public_apk` (ChromePublic.apk)
* Used for local development and tests (simpler than using bundle targets).
* Same configuration as chrome_modern_public_bundle.
2. `chrome_modern_public_bundle` (MonochromePublic.aab)
* `minSdkVersion=21` (Lollipop).
* Uses [Crazy Linker](https://cs.chromium.org/chromium/src/base/android/linker/BUILD.gn?rcl=6bb29391a86f2be58c626170156cbfaa2cbc5c91&l=9).
* Stores libchrome.so uncompressed within the APK.
* This APK is bigger, but the installation size is smaller since there is
no need to extract the .so file.
* Historically known as "chrome_modern_public_apk".
2. `monochrome_public_apk` (MonochromePublic.apk)
* Stores native library with "crazy." prefix to prevent extraction.
3. `monochrome_public_bundle` (MonochromePublic.aab)
* `minSdkVersion=24` (Nougat).
* Contains both WebView and Chrome within the same APK.
* This APK is even bigger, but much smaller than SystemWebView.apk + ChromePublic.apk.
* Stores libmonochrome.so uncompressed within the APK.
* This bundle is larger than ChromeModern, but much smaller than SUM(SystemWebView, ChromeModern)
* Does not use Crazy Linker (WebView requires system linker).
* But system linker supports crazy linker features now anyways.
3. `trichrome_chrome_bundle` and `trichrome_library_apk` (TrichromeChrome.aab and TrichromeLibrary.apk)
4. `trichrome_chrome_bundle` and `trichrome_library_apk` (TrichromeChrome.aab and TrichromeLibrary.apk)
* `minSdkVersion=Q` (Q).
* TrichromeChrome contains only the Chrome code that is not shared with WebView.
* TrichromeLibrary contains the shared code and is a "static shared library APK", which must be installed prior to TrichromeChrome.
* TrichromeLibrary contains the shared code and is a "static shared library APK".
* Stores libmonochrome.so uncompressed within TrichromeLibrary.apk.
* Does not use Crazy Linker (WebView requires system linker).
* But system linker supports crazy linker features now anyways.
* Uses `android_dlopen_ext` to load native libraries with shared RELRO's
**Note**: These instructions use `chrome_public_apk`, but either of the other
two targets can be substituted.
**Note**: These instructions use `chrome_public_apk`, but any of the other
targets can be substituted.
**Note**: These targets are actually the open-source equivalents to the
closed-source targets that get shipped to the Play Store.

@ -5,13 +5,28 @@ Chrome on Android.
[TOC]
## Library Packaging
* Android L & M (ChromePublic.apk):
* `libchrome.so` is stored uncompressed within the apk (with the name `crazy.libchrome.so` to avoid extraction).
* It is loaded directly from the apk (without extracting) by `mmap()`'ing it.
* Android N, O & P (MonochromePublic.apk):
* `libmonochrome.so` is stored uncompressed (AndroidManifest.xml attribute disables extraction) and loaded directly from the apk (functionality now supported by the system linker).
* Android Q (TrichromeChrome.aab+TrichromeLibrary.apk):
* `libmonochrome.so` is stored in the shared library apk (TrichromeLibrary.apk) instead of in the Chrome apk, so that it can be shared with TrichromeWebView. It's stored uncompressed and loaded directly from the apk the same way as on N-P. Trichrome uses the same native library as Monochrome, so it's still called `libmonochrome.so`.
* Android L & M (ChromeModernPublic.aab):
* `libchrome.so` is stored uncompressed within the apk (with the name
`crazy.libchrome.so` to avoid extraction).
* It is loaded directly from the apk via `libchromium_android_linker.so`.
* Only JNI_OnLoad is exported, since manual JNI registration is required
(see [//base/android/jni_generator/README.md]).
* Android N, O & P (MonochromePublic.aab):
* `libmonochrome.so` is stored uncompressed within the apk (an
AndroidManifest.xml attribute disables extraction).
* It is loaded directly from the apk by the system linker.
* It exports all JNI symbols and does not use explicit JNI registration.
* It is not loaded by `libchromium_android_linker.so` and relies on the
system's webview zygote for RELRO sharing.
* Android Q (TrichromeChrome.aab + TrichromeLibrary.apk):
* Trichrome uses the exact same native library as Monochrome:
`libmonochrome.so`.
* `libmonochrome.so` is stored in the shared library (TrichromeLibrary.apk)
so that it can be shared with TrichromeWebView.
* It is loaded by `libchromium_android_linker.so` using
`android_dlopen_ext()` to enable RELRO sharing.
[//base/android/jni_generator/README.md]: /base/android/jni_generator/README.md
## Build Variants (eg. monochrome_64_32_apk)
The packaging above extends to cover both 32-bit and 64-bit device
@ -180,10 +195,15 @@ Builds on | Variant | Chrome | Library | Webview
* For renderer processes, the OS starts all Monochrome renderer processes by `fork()`ing the WebView zygote rather than the normal application zygote.
* In this case, RELRO sharing would be redundant since the entire process' memory is shared with the zygote with copy-on-write semantics.
* For Android Q+ (Trichrome):
* For non-renderer processes, TrichromeChrome no longer shares its RELRO data with WebView and no RELRO sharing occurs. TrichromeWebView works the same way as on Android N-P.
* For renderer processes, TrichromeChrome `fork()`s from a chrome-specific app zygote. `libmonochrome.so` is loaded in the zygote before `fork()`.
* Similar to O-P, app zygote provides copy-on-write memory semantics so RELRO sharing is redundant.
* For renderer processes, TrichromeWebView works the same way as on Android N-P.
* TrichromeWebView works the same way as on Android N-P.
* TrichromeChrome uses `android_dlopen_ext()` and `ASharedMemory_create()` to
perform RELRO sharing, and then relies on a subsequent call to
`System.loadLibrary()` to enable JNI method resolution without loading the
library a second time.
* For renderer processes, TrichromeChrome `fork()`s from a chrome-specific
app zygote. `libmonochrome.so` is loaded in the zygote before `fork()`.
* Similar to O-P, app zygote provides copy-on-write memory semantics so
RELRO sharing is redundant.
## Partitioned libraries
Some Chrome code is placed in feature-specific libraries and delivered via