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