xref: /aosp_15_r20/external/angle/build/android/incremental_install/README.md (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# Incremental Install
2*8975f5c5SAndroid Build Coastguard Worker
3*8975f5c5SAndroid Build Coastguard WorkerIncremental Install is a way of building & deploying an APK that tries to
4*8975f5c5SAndroid Build Coastguard Workerminimize the time it takes to make a change and see that change running on
5*8975f5c5SAndroid Build Coastguard Workerdevice. They work best with `is_component_build=true`, and do *not* require a
6*8975f5c5SAndroid Build Coastguard Workerrooted device.
7*8975f5c5SAndroid Build Coastguard Worker
8*8975f5c5SAndroid Build Coastguard Worker## Building
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard WorkerAdd the gn arg:
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker    incremental_install = true
13*8975f5c5SAndroid Build Coastguard Worker
14*8975f5c5SAndroid Build Coastguard WorkerThis causes all apks to be built as incremental except for denylisted ones.
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard Worker## Running
17*8975f5c5SAndroid Build Coastguard Worker
18*8975f5c5SAndroid Build Coastguard WorkerIt is not enough to `adb install` them. You must use the generated wrapper
19*8975f5c5SAndroid Build Coastguard Workerscript:
20*8975f5c5SAndroid Build Coastguard Worker
21*8975f5c5SAndroid Build Coastguard Worker    out/Debug/bin/your_apk run
22*8975f5c5SAndroid Build Coastguard Worker    out/Debug/bin/run_chrome_public_test_apk  # Automatically sets --fast-local-dev
23*8975f5c5SAndroid Build Coastguard Worker
24*8975f5c5SAndroid Build Coastguard Worker# How it Works
25*8975f5c5SAndroid Build Coastguard Worker
26*8975f5c5SAndroid Build Coastguard Worker## Overview
27*8975f5c5SAndroid Build Coastguard Worker
28*8975f5c5SAndroid Build Coastguard WorkerThe basic idea is to sideload .dex and .so files to `/data/local/tmp` rather
29*8975f5c5SAndroid Build Coastguard Workerthan bundling them in the .apk. Then, when making a change, only the changed
30*8975f5c5SAndroid Build Coastguard Worker.dex / .so needs to be pushed to the device.
31*8975f5c5SAndroid Build Coastguard Worker
32*8975f5c5SAndroid Build Coastguard WorkerFaster Builds:
33*8975f5c5SAndroid Build Coastguard Worker
34*8975f5c5SAndroid Build Coastguard Worker * No `final_dex` step (where all .dex files are merged into one)
35*8975f5c5SAndroid Build Coastguard Worker * No need to rebuild .apk for code-only changes (but required for resources)
36*8975f5c5SAndroid Build Coastguard Worker * Apks sign faster because they are smaller.
37*8975f5c5SAndroid Build Coastguard Worker
38*8975f5c5SAndroid Build Coastguard WorkerFaster Installs:
39*8975f5c5SAndroid Build Coastguard Worker
40*8975f5c5SAndroid Build Coastguard Worker * The .apk is smaller, and so faster to verify.
41*8975f5c5SAndroid Build Coastguard Worker * No need to run `adb install` for code-only changes.
42*8975f5c5SAndroid Build Coastguard Worker * Only changed .so / .dex files are pushed. MD5s of existing on-device files
43*8975f5c5SAndroid Build Coastguard Worker   are cached on host computer.
44*8975f5c5SAndroid Build Coastguard Worker
45*8975f5c5SAndroid Build Coastguard WorkerSlower Initial Runs:
46*8975f5c5SAndroid Build Coastguard Worker
47*8975f5c5SAndroid Build Coastguard Worker * The first time you run an incremental .apk, the `DexOpt` needs to run on all
48*8975f5c5SAndroid Build Coastguard Worker   .dex files. This step is normally done during `adb install`, but is done on
49*8975f5c5SAndroid Build Coastguard Worker   start-up for incremental apks.
50*8975f5c5SAndroid Build Coastguard Worker   * DexOpt results are cached, so subsequent runs are faster.
51*8975f5c5SAndroid Build Coastguard Worker   * The slowdown varies significantly based on the Android version. Android O+
52*8975f5c5SAndroid Build Coastguard Worker     has almost no visible slow-down.
53*8975f5c5SAndroid Build Coastguard Worker
54*8975f5c5SAndroid Build Coastguard WorkerCaveats:
55*8975f5c5SAndroid Build Coastguard Worker * Isolated processes (on L+) are incompatible with incremental install. As a
56*8975f5c5SAndroid Build Coastguard Worker   work-around, isolated processes are disabled when building incremental apks.
57*8975f5c5SAndroid Build Coastguard Worker * Android resources, assets, and `loadable_modules` are not sideloaded (they
58*8975f5c5SAndroid Build Coastguard Worker   remain in the apk), so builds & installs that modify any of these are not as
59*8975f5c5SAndroid Build Coastguard Worker   fast as those that modify only .java / .cc.
60*8975f5c5SAndroid Build Coastguard Worker * Since files are sideloaded to `/data/local/tmp`, you need to use the wrapper
61*8975f5c5SAndroid Build Coastguard Worker   scripts to uninstall them fully. E.g.:
62*8975f5c5SAndroid Build Coastguard Worker   ```shell
63*8975f5c5SAndroid Build Coastguard Worker   out/Default/bin/chrome_public_apk uninstall
64*8975f5c5SAndroid Build Coastguard Worker   ```
65*8975f5c5SAndroid Build Coastguard Worker * `AppComponentFactory.instantiateClassLoader()` is not supported.
66*8975f5c5SAndroid Build Coastguard Worker
67*8975f5c5SAndroid Build Coastguard Worker## The Code
68*8975f5c5SAndroid Build Coastguard Worker
69*8975f5c5SAndroid Build Coastguard WorkerAll incremental apks have the same classes.dex, which is built from:
70*8975f5c5SAndroid Build Coastguard Worker
71*8975f5c5SAndroid Build Coastguard Worker    //build/android/incremental_install:bootstrap_java
72*8975f5c5SAndroid Build Coastguard Worker
73*8975f5c5SAndroid Build Coastguard WorkerThey also have a transformed `AndroidManifest.xml`, which overrides the the
74*8975f5c5SAndroid Build Coastguard Workermain application class and any instrumentation classes so that they instead
75*8975f5c5SAndroid Build Coastguard Workerpoint to `BootstrapApplication`. This is built by:
76*8975f5c5SAndroid Build Coastguard Worker
77*8975f5c5SAndroid Build Coastguard Worker    //build/android/incremental_install/generate_android_manifest.py
78*8975f5c5SAndroid Build Coastguard Worker
79*8975f5c5SAndroid Build Coastguard WorkerWrapper scripts and install logic is contained in:
80*8975f5c5SAndroid Build Coastguard Worker
81*8975f5c5SAndroid Build Coastguard Worker    //build/android/incremental_install/create_install_script.py
82*8975f5c5SAndroid Build Coastguard Worker    //build/android/incremental_install/installer.py
83*8975f5c5SAndroid Build Coastguard Worker
84*8975f5c5SAndroid Build Coastguard WorkerFinally, GN logic for incremental apks is sprinkled throughout.
85