1# ANGLE for Android 2 3**Important note**: Android builds currently require Linux. 4 5## Setting up the ANGLE build for Android 6 7Please follow the instructions in [DevSetup](DevSetup.md) to check out and bootstrap ANGLE with 8gclient. Then edit your `.gclient` to add `target_os = ['android']` to check out Android 9dependencies. Then run `gclient sync` to download all required sources and packages. 10 11The following command will open a text editor to populate GN args for an Android Release build: 12``` 13gn args out/Android 14``` 15 16Once the editor is up, paste the following GN args to generate an Android build, and save the file. 17``` 18target_os = "android" 19target_cpu = "arm64" 20is_component_build = false 21is_debug = false 22angle_assert_always_on = true # Recommended for debugging. Turn off for performance. 23use_remoteexec = true # Googlers-only! If you're not a Googler remove this. 24``` 25 26More targeted GN arg combinations can be found [below](#android-gn-args-combinations). 27 28If you run into any problems with the above, you can copy the canonical args from CI: 29 - Visit the ANGLE [CI Waterfall](https://ci.chromium.org/p/angle/g/ci/console). 30 - Open any recent Android build. 31 - Expand the for "lookup GN args" step and copy the GN args. 32 - If you are not a Googler, also omit the `use_remoteexec` flag. 33 34## Building ANGLE for Android 35 36Build all ANGLE targets using the following command: 37 38``` 39autoninja -C out/Android 40``` 41 42Most ANGLE build targets are supported. We do not support the ANGLE samples on 43Android currently. ANGLE tests will be in your `out/Android` directory, and can 44be run with various options. For instance, angle perftests can be run with: 45 46``` 47./out/Android/angle_perftests --verbose --local-output --gtest_filter=DrawCallPerf* 48``` 49 50Additional details are in [Android Test Instructions][AndroidTest]. 51 52Additional Android dEQP notes can be found in [Running dEQP on Android](dEQP.md#Running-dEQP-on-Android). 53 54If you are targeting WebGL and want to run with ANGLE, you will need to build within a full 55Chromium checkout. Please follow the [Chromium build instructions for Android][ChromeAndroid]. 56Also refer to the [ANGLE Guide][ANGLEChrome] on how to work with Top of Tree ANGLE in Chromium. 57Build the `chrome_public_apk` target, and follow the [GPU Testing][GPU Testing] doc, using 58`--browser=android-chromium`. Make sure to set your `CHROMIUM_OUT_DIR` environment variable, so 59that your browser is found, otherwise the tests will use the stock browser. 60 61[AndroidTest]: https://chromium.googlesource.com/chromium/src/+/main/docs/testing/android_test_instructions.md 62[GPU Testing]: http://www.chromium.org/developers/testing/gpu-testing#TOC-Running-the-GPU-Tests-Locally 63[ChromeAndroid]: https://chromium.googlesource.com/chromium/src/+/main/docs/android_build_instructions.md 64[ANGLEChrome]: BuildingAngleForChromiumDevelopment.md 65 66## Using ANGLE as the Android OpenGL ES driver 67 68Starting with Android 10 (Q), you can load ANGLE as your device's OpenGL ES driver. 69 70`== Important Note ==` You can only run this ANGLE with *DEBUGGABLE APPS* or when you have 71*ROOT ACCESS*. Debuggable apps are [marked debuggable][Debuggable] in the manifest. For root 72access, see the [Android documentation][UserDebug] for how to build from source. 73 74To build the ANGLE APK, you must first bootstrap your build by following the steps 75[above](#ANGLE-for-Android). The steps below will result in an APK that contains the ANGLE 76libraries and can be installed on any Android 10+ build. 77 78Apps can be opted in to ANGLE [one at a time](#ANGLE-for-a-single-OpenGL-ES-app), in 79[groups](#ANGLE-for-multiple-OpenGL-ES-apps), or [globally](#ANGLE-for-all-OpenGL-ES-apps). The 80apps must be launched by the Java runtime since the libraries are discovered within an installed 81package. This means ANGLE cannot be used by native executables or SurfaceFlinger at this time. 82 83## Building the ANGLE APK 84 85Using `gn args` from above, you can build the ANGLE apk using: 86``` 87autoninja -C out/Android angle_apks 88``` 89 90## Installing the ANGLE APK 91 92``` 93adb install -r -d --force-queryable out/Android/apks/AngleLibraries.apk 94``` 95You can verify installation by looking for the package name: 96``` 97$ adb shell pm path org.chromium.angle 98package:/data/app/org.chromium.angle-HpkUceNFjoLYKPbIVxFWLQ==/base.apk 99``` 100 101Note that `angle_debug_package` must be set to `org.chromium.angle` for this apk to be loaded. 102 103## Selecting ANGLE as the OpenGL ES driver 104 105For debuggable applications or root users, you can tell the platform to load ANGLE libraries from 106the installed package. 107``` 108adb shell settings put global angle_debug_package org.chromium.angle 109``` 110Remember that ANGLE can only be used by applications launched by the Java runtime. 111 112Note: Side-loading apk on Cuttlefish currently requires [special setup](#Cuttlefish-setup) 113 114## ANGLE driver choices 115 116There are multiple values you can use for selecting which OpenGL ES driver is loaded by the platform. 117 118The following values are supported for `angle_gl_driver_selection_values`: 119 - `angle` : Use ANGLE. 120 - `native` : Use the native OpenGL ES driver. 121 - `default` : Use the default driver. This allows the platform to decide which driver to use. 122 123In each section below, replace `<driver>` with one of the values above. 124 125### ANGLE for a *single* OpenGL ES app 126 127``` 128adb shell settings put global angle_gl_driver_selection_pkgs <package name> 129adb shell settings put global angle_gl_driver_selection_values <driver> 130``` 131 132### ANGLE for *multiple* OpenGL ES apps 133 134Similar to selecting a single app, you can select multiple applications by listing their package 135names and driver choice in comma separated lists. Note the lists must be the same length, one 136driver choice per package name. 137``` 138adb shell settings put global angle_gl_driver_selection_pkgs <package name 1>,<package name 2>,<package name 3>,... 139adb shell settings put global angle_gl_driver_selection_values <driver 1>,<driver 2>,<driver 3>,... 140``` 141 142### ANGLE for *all* OpenGL ES apps 143 144`Note: This method only works on a device with root access.` 145 146Enable: 147``` 148adb shell settings put global angle_gl_driver_all_angle 1 149``` 150Disable: 151``` 152adb shell settings put global angle_gl_driver_all_angle 0 153``` 154 155## Check for success 156 157Check to see that ANGLE was loaded by your application: 158``` 159$ adb logcat -d | grep ANGLE 160V GraphicsEnvironment: ANGLE developer option for <package name>: angle 161I GraphicsEnvironment: ANGLE package enabled: org.chromium.angle 162I ANGLE : Version (2.1.0.f87fac56d22f), Renderer (Vulkan 1.1.87(Adreno (TM) 615 (0x06010501))) 163``` 164 165Note that this might be logged by the built-in ANGLE and not the installed apk if `angle_debug_package` wasn't set. 166 167## Clean up 168 169Settings persist across reboots, so it is a good idea to delete them when finished. 170``` 171adb shell settings delete global angle_debug_package 172adb shell settings delete global angle_gl_driver_all_angle 173adb shell settings delete global angle_gl_driver_selection_pkgs 174adb shell settings delete global angle_gl_driver_selection_values 175``` 176 177## Troubleshooting 178 179If your application is not debuggable or you are not root, you may see an error like this in the log: 180``` 181$ adb logcat -d | grep ANGLE 182V GraphicsEnvironment: ANGLE developer option for <package name>: angle 183E GraphicsEnvironment: Invalid number of ANGLE packages. Required: 1, Found: 0 184E GraphicsEnvironment: Failed to find ANGLE package. 185``` 186Double check that you are root, or that your application is [marked debuggable][Debuggable]. 187 188## Android GN args combinations 189 190The [above](#angle-gn-args-for-android) GN args only modify default values to generate a Debug 191build for Android. Below are some common configurations used for different scenarios. 192 193To determine what is different from default, you can point the following command at your target 194directory. It will show the list of gn args in use, where they came from, their current value, 195and their default values. 196``` 197gn args --list <dir> 198``` 199 200### Performance config 201 202This config is designed to get maximum performance by disabling debug configs and validation layers. 203Note: The oddly named `is_official_build` is a more aggressive optimization level than `Release`. Its name is historical. 204``` 205target_os = "android" 206target_cpu = "arm64" 207angle_enable_vulkan = true 208is_component_build = false 209is_official_build = true 210is_debug = false 211``` 212 213### Debug config 214 215This config is useful for quickly ensuring Vulkan is running cleanly. It disables debug, but 216enables asserts and allows validation errors. 217``` 218target_os = "android" 219target_cpu = "arm64" 220is_component_build = false 221is_debug = true 222``` 223 224#### Application Compatibility 225 226Application compatibility may be increased by enabling non-conformant features and extensions with 227a GN arg: 228 229``` 230angle_expose_non_conformant_extensions_and_versions = true 231``` 232 233### Cuttlefish setup 234 235Cuttlefish uses ANGLE as a system GL driver, on top of SwiftShader. It also uses SkiaGL (not SkiaVk) 236due to a SwiftShader limitation. This enables preloading of GL libs - so in this case, ANGLE - into Zygote, 237which with the current implementation of the loader results in system libs being loaded instead of 238loading them from the debug apk. To workaround, a custom library name can be set via a GN arg: 239 240``` 241angle_libs_suffix = _angle_in_apk 242``` 243 244and enabled in the platform with this setting (mind the lack of a leading underscore compared to the above): 245 246``` 247adb shell setprop debug.angle.libs.suffix angle_in_apk 248``` 249 250## Accessing ANGLE traces 251 252To sync and build the ANGLE traces, jump to [ANGLE Restricted Traces](https://chromium.googlesource.com/angle/angle.git/+/HEAD/src/tests/restricted_traces/README.md#angle-restricted-traces). 253 254## Command line for launching chrome on Android 255 256[This Makefile](https://github.com/phuang/test/blob/main/chromium/Makefile) contains many useful 257command lines for launching chrome. 258 259Targets run_chrome_public_apk_* is for launching chrome on Android. 260 261To use this Makefile, download it into chrome build tree, and use below commands (for more targets please check Makefile) 262``` 263# To edit gn args 264$ make args OUT=out_android/Release # The OUT can be set in Makefile instead of passing it in command line 265 266# Build and run chrome on Android device with GLRenderer 267$ make run_chrome_public_apk_gl 268 269# Build and run chrome on Android device with SkiaRenderer 270$ make run_chrome_public_apk_skia 271 272# Run adb logcat 273$ make adb_logcat 274 275# Symbolize Android crash stack 276$ make android_symbol 277 278# Build and run gpu_unittests 279$ make gpu_unittests GTEST_FILTER="gtest-filters" # If GTEST_FILTER is not specified, all tests will be run. 280``` 281 282[Debuggable]: https://developer.android.com/guide/topics/manifest/application-element#debug 283[UserDebug]: https://source.android.com/setup/build/building 284