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 112## ANGLE driver choices 113 114There are multiple values you can use for selecting which OpenGL ES driver is loaded by the platform. 115 116The following values are supported for `angle_gl_driver_selection_values`: 117 - `angle` : Use ANGLE. 118 - `native` : Use the native OpenGL ES driver. 119 - `default` : Use the default driver. This allows the platform to decide which driver to use. 120 121In each section below, replace `<driver>` with one of the values above. 122 123### ANGLE for a *single* OpenGL ES app 124 125``` 126adb shell settings put global angle_gl_driver_selection_pkgs <package name> 127adb shell settings put global angle_gl_driver_selection_values <driver> 128``` 129 130### ANGLE for *multiple* OpenGL ES apps 131 132Similar to selecting a single app, you can select multiple applications by listing their package 133names and driver choice in comma separated lists. Note the lists must be the same length, one 134driver choice per package name. 135``` 136adb shell settings put global angle_gl_driver_selection_pkgs <package name 1>,<package name 2>,<package name 3>,... 137adb shell settings put global angle_gl_driver_selection_values <driver 1>,<driver 2>,<driver 3>,... 138``` 139 140### ANGLE for *all* OpenGL ES apps 141 142`Note: This method only works on a device with root access.` 143 144Enable: 145``` 146adb shell settings put global angle_gl_driver_all_angle 1 147``` 148Disable: 149``` 150adb shell settings put global angle_gl_driver_all_angle 0 151``` 152 153## Check for success 154 155Check to see that ANGLE was loaded by your application: 156``` 157$ adb logcat -d | grep ANGLE 158V GraphicsEnvironment: ANGLE developer option for <package name>: angle 159I GraphicsEnvironment: ANGLE package enabled: org.chromium.angle 160I ANGLE : Version (2.1.0.f87fac56d22f), Renderer (Vulkan 1.1.87(Adreno (TM) 615 (0x06010501))) 161``` 162 163Note that this might be logged by the built-in ANGLE and not the installed apk if `angle_debug_package` wasn't set. 164 165## Clean up 166 167Settings persist across reboots, so it is a good idea to delete them when finished. 168``` 169adb shell settings delete global angle_debug_package 170adb shell settings delete global angle_gl_driver_all_angle 171adb shell settings delete global angle_gl_driver_selection_pkgs 172adb shell settings delete global angle_gl_driver_selection_values 173``` 174 175## Troubleshooting 176 177If your application is not debuggable or you are not root, you may see an error like this in the log: 178``` 179$ adb logcat -d | grep ANGLE 180V GraphicsEnvironment: ANGLE developer option for <package name>: angle 181E GraphicsEnvironment: Invalid number of ANGLE packages. Required: 1, Found: 0 182E GraphicsEnvironment: Failed to find ANGLE package. 183``` 184Double check that you are root, or that your application is [marked debuggable][Debuggable]. 185 186## Android GN args combinations 187 188The [above](#angle-gn-args-for-android) GN args only modify default values to generate a Debug 189build for Android. Below are some common configurations used for different scenarios. 190 191To determine what is different from default, you can point the following command at your target 192directory. It will show the list of gn args in use, where they came from, their current value, 193and their default values. 194``` 195gn args --list <dir> 196``` 197 198### Performance config 199 200This config is designed to get maximum performance by disabling debug configs and validation layers. 201Note: The oddly named `is_official_build` is a more aggressive optimization level than `Release`. Its name is historical. 202``` 203target_os = "android" 204target_cpu = "arm64" 205angle_enable_vulkan = true 206is_component_build = false 207is_official_build = true 208is_debug = false 209``` 210 211### Debug config 212 213This config is useful for quickly ensuring Vulkan is running cleanly. It disables debug, but 214enables asserts and allows validation errors. 215``` 216target_os = "android" 217target_cpu = "arm64" 218is_component_build = false 219is_debug = true 220``` 221 222#### Application Compatibility 223 224Application compatibility may be increased by enabling non-conformant features and extensions with 225a GN arg: 226 227``` 228angle_expose_non_conformant_extensions_and_versions = true 229``` 230 231## Accessing ANGLE traces 232 233To 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). 234 235## Command line for launching chrome on Android 236 237[This Makefile](https://github.com/phuang/test/blob/main/chromium/Makefile) contains many useful 238command lines for launching chrome. 239 240Targets run_chrome_public_apk_* is for launching chrome on Android. 241 242To use this Makefile, download it into chrome build tree, and use below commands (for more targets please check Makefile) 243``` 244# To edit gn args 245$ make args OUT=out_android/Release # The OUT can be set in Makefile instead of passing it in command line 246 247# Build and run chrome on Android device with GLRenderer 248$ make run_chrome_public_apk_gl 249 250# Build and run chrome on Android device with SkiaRenderer 251$ make run_chrome_public_apk_skia 252 253# Run adb logcat 254$ make adb_logcat 255 256# Symbolize Android crash stack 257$ make android_symbol 258 259# Build and run gpu_unittests 260$ make gpu_unittests GTEST_FILTER="gtest-filters" # If GTEST_FILTER is not specified, all tests will be run. 261``` 262 263[Debuggable]: https://developer.android.com/guide/topics/manifest/application-element#debug 264[UserDebug]: https://source.android.com/setup/build/building 265