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