1# ANGLE for Android 2 3Building ANGLE for Android is heavily dependent on the Chromium toolchain. It is not currently possible to build ANGLE for Android without a Chromium checkout. See http://anglebug.com/2344 for more details on why. 4 5From a Linux platform (the only platform that Chromium for Android supports), follow the steps in 6[Checking out and building Chromium for Android](https://chromium.googlesource.com/chromium/src/+/master/docs/android_build_instructions.md). 7 8Name your output directories `out/Debug` and `out/Release`, because Chromium GPU tests look for browser binaries in these folders. Replacing '[Debug|Release]' with other names seems to be OK when working with multiple build configurations. 9 10The following GN args are known to work well for Release and Debug configurations. 11 12Debug: 13``` 14$ gn args out/Debug 15``` 16``` 17target_os = "android" 18target_cpu = "arm64" 19android32_ndk_api_level = 26 20android64_ndk_api_level = 26 21angle_libs_suffix = "_angle" 22ffmpeg_branding = "Chrome" 23is_component_build = false 24symbol_level = 1 25is_debug = true 26dcheck_always_on = true 27angle_enable_vulkan = true 28angle_enable_vulkan_validation_layers = true 29angle_enable_gl = false 30``` 31Release: 32``` 33$ gn args out/Release 34``` 35``` 36target_os = "android" 37target_cpu = "arm64" 38android32_ndk_api_level = 26 39android64_ndk_api_level = 26 40angle_libs_suffix = "_angle" 41ffmpeg_branding = "Chrome" 42is_component_build = false 43symbol_level = 0 44strip_debug_info = true 45is_debug = false 46is_official_build = true # enables level of optimization beyond release 47dcheck_always_on = false 48angle_enable_vulkan = true 49angle_enable_vulkan_validation_layers = false 50angle_enable_gl = false 51enable_resource_whitelist_generation = false 52``` 53 54If you run into any problems with the above, you may be able to pull newer GN args from an official Android bot on [GPU.FYI waterfall](https://ci.chromium.org/p/chromium/g/chromium.gpu.fyi/console). 55 - Look for `generate_build_files` step output of that bot. 56 - Remove `goma_dir` flag. 57 58Build an ANGLE target using the following command: 59 60``` 61autoninja -C out/Debug <target> 62``` 63or 64``` 65autoninja -C out/Release <target> 66``` 67 68The following ANGLE build targets are supported: 69 70``` 71angle 72angle_apks 73angle_deqp_gles2_tests 74angle_deqp_khr_gles2_tests 75angle_deqp_gles3_tests 76angle_deqp_khr_gles3_tests 77angle_deqp_gles31_tests 78angle_deqp_khr_gles31_tests 79angle_deqp_egl_tests 80angle_end2end_tests 81angle_perftests 82angle_unittests 83angle_white_box_perftests 84angle_white_box_tests 85``` 86ANGLE tests will be in your out/<target> directory, and can be run with various options. For instance, angle perftests can be run with: 87``` 88./out/Debug/angle_perftests --use-angle=vulkan --verbose --local-output --gtest_filter="*foo*" 89``` 90 91Additional details are in [Android Test Instructions](https://chromium.googlesource.com/chromium/src/+/master/docs/testing/android_test_instructions.md). 92 93Additional Android dEQP notes can be found in [Running dEQP on Android](dEQP.md#Running-dEQP-on-Android). 94 95If you are targeting WebGL and want to run GPU telemetry tests, build `chrome_public_apk` target. Then follow [GPU Testing](http://www.chromium.org/developers/testing/gpu-testing#TOC-Running-the-GPU-Tests-Locally) doc, using `--browser=android-chromium` argument. Make sure to set your `CHROMIUM_OUT_DIR` environment variable, so that your browser is found, otherwise the stock one will run. Also, follow [How to build ANGLE in Chromium for dev](BuildingAngleForChromiumDevelopment.md) to work with Top of Tree ANGLE in Chromium. 96 97## Using ANGLE as the Android OpenGL ES driver 98 99Starting with Android 10 (Q), ANGLE can be loaded as the OpenGL ES driver. 100 101`== Important Note ==` ANGLE built this way can only be used for *DEBUGGABLE APPS* (i.e. [marked debuggable](https://developer.android.com/guide/topics/manifest/application-element#debug) in the manifest) or users with *ROOT ACCESS* (i.e. a [userdebug](https://source.android.com/setup/build/building) build). 102 103To build the ANGLE APK, you must first bootstrap your build by following the steps [above](#ANGLE-for-Android). The steps below will result in an APK that contains the ANGLE libraries and can be installed on any Android 10+ build. 104 105Apps can be opted in to ANGLE [one at a time](#ANGLE-for-a-single-OpenGL-ES-app), in [groups](#ANGLE-for-multiple-OpenGL-ES-apps), or [globally](#ANGLE-for-all-OpenGL-ES-apps), but they must be launched by the Java runtime since the libraries are discovered within an installed package. This means ANGLE cannot be used by native executables or SurfaceFlinger at this time. 106 107## Build the ANGLE APK 108 109Using 'gn args` from above, you can build the ANGLE apk using: 110``` 111autoninja -C out/Debug angle_apks 112``` 113## Install the ANGLE APK 114``` 115adb install out/Debug/apks/AngleLibraries.apk 116``` 117You can verify installation by looking for the package name: 118``` 119$ adb shell pm path com.chromium.angle 120package:/data/app/com.chromium.angle-HpkUceNFjoLYKPbIVxFWLQ==/base.apk 121``` 122## Selecting ANGLE as the OpenGL ES driver 123 124For debuggable applications or root users, you can tell the platform to load ANGLE libraries from the installed package. 125``` 126adb shell settings put global angle_debug_package com.chromium.angle 127``` 128Remember that ANGLE can only be used by applications launched by the Java runtime. 129 130## ANGLE driver choices 131There are multiple values you can use for selecting which OpenGL ES driver is loaded by the platform. 132 133The following values are supported for `angle_gl_driver_selection_values`: 134 - `angle` : Use ANGLE. 135 - `native` : Use the native OpenGL ES driver. 136 - `default` : Use the default driver. This allows the platform to decide which driver to use. 137 138In each section below, replace `<driver>` with one of the values above. 139 140## ANGLE for a *single* OpenGL ES app 141``` 142adb shell settings put global angle_gl_driver_selection_pkgs <package name> 143adb shell settings put global angle_gl_driver_selection_values <driver> 144``` 145## ANGLE for *multiple* OpenGL ES apps 146Similar to selecting a single app, you can select multiple applications by listing their package names and driver choice in comma separated lists. Note the lists must be the same length, one driver choice per package name. 147``` 148adb shell settings put global angle_gl_driver_selection_pkgs <package name 1>,<package name 2>,<package name 3>,... 149adb shell settings put global angle_gl_driver_selection_values <driver 1>,<driver 2>,<driver 3>,... 150``` 151## ANGLE for *all* OpenGL ES apps 152Enable: 153``` 154adb shell settings put global angle_gl_driver_all_angle 1 155``` 156Disable: 157``` 158adb shell settings put global angle_gl_driver_all_angle 0 159``` 160## Check for success 161Check to see that ANGLE was loaded by your application: 162``` 163$ adb logcat -d | grep ANGLE 164V GraphicsEnvironment: ANGLE developer option for <package name>: angle 165I GraphicsEnvironment: ANGLE package enabled: com.chromium.angle 166I ANGLE : Version (2.1.0.f87fac56d22f), Renderer (Vulkan 1.1.87(Adreno (TM) 615 (0x06010501))) 167``` 168## Clean up 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## Troubleshooting 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](https://developer.android.com/guide/topics/manifest/application-element#debug). 185