blob: 84896852ba1ab0bee1de53daa69e149d90c29691 [file] [log] [blame] [view]
jingwen2f963272018-04-11 20:18:44 -07001---
2layout: documentation
3title: Android Instrumentation Tests
4---
5
6# Android Instrumentation Tests
7
8_If you're new to Bazel, please start with the [Building Android with
Jingwen Chen0f4544d2018-12-14 16:28:16 -08009Bazel](tutorial/android-app.html) tutorial._
jingwen2f963272018-04-11 20:18:44 -070010
11![Running Android instrumentation tests in parallel](/assets/android_test.gif)
12
Jingwen Chen0f4544d2018-12-14 16:28:16 -080013[`android_instrumentation_test`](be/android.html#android_instrumentation_test)
jingwen2f963272018-04-11 20:18:44 -070014allows developers to test their apps on Android emulators and devices.
15It utilizes real Android framework APIs and the Android Test Library.
16
17For hermeticity and reproducibility, Bazel creates and launches Android
18emulators in a sandbox, ensuring that tests always run from a clean state. Each
19test gets an isolated emulator instance, allowing tests to run in parallel
20without passing states between them.
21
22For more information on Android instrumentation tests, check out the [Android
23developer
24documentation](https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html).
25
jingwen5ff94b72018-08-08 13:04:52 -070026Please file issues in the [GitHub issue tracker](https://github.com/bazelbuild/bazel/issues).
jingwen2f963272018-04-11 20:18:44 -070027
Googler1403a162021-01-22 13:42:50 -080028## How it works
jingwen2f963272018-04-11 20:18:44 -070029
30When you run `bazel test` on an `android_instrumentation_test` target for the
31first time, Bazel performs the following steps:
32
331. Builds the test APK, APK under test, and their transitive dependencies
342. Creates, boots, and caches clean emulator states
353. Starts the emulator
364. Installs the APKs
375. Runs tests utilizing the [Android Test Orchestrator](https://developer.android.com/training/testing/junit-runner.html#using-android-test-orchestrator)
386. Shuts down the emulator
397. Reports the results
40
41In subsequent test runs, Bazel boots the emulator from the clean, cached state
42created in step 2, so there are no leftover states from previous runs. Caching
43emulator state also speeds up test runs.
44
Googler1403a162021-01-22 13:42:50 -080045## Prerequisites
jingwen2f963272018-04-11 20:18:44 -070046
jingwen7c70d822019-01-08 15:12:29 -080047Ensure your environment satisfies the following prerequisites:
jingwen2f963272018-04-11 20:18:44 -070048
Philipp Wollermann927d32d2019-06-17 13:35:55 -070049- **Linux**. Tested on Ubuntu 16.04, and 18.04.
jingwen2f963272018-04-11 20:18:44 -070050
51- **Bazel 0.12.0** or later. Verify the version by running `bazel info release`.
52
53```
54$ bazel info release
55release 0.12.0
56```
57
58- **KVM**. Bazel requires emulators to have [hardware
59 acceleration](https://developer.android.com/studio/run/emulator-acceleration.html#accel-check)
60 with KVM on Linux. You can follow these
61 [installation instructions](https://help.ubuntu.com/community/KVM/Installation)
62 for Ubuntu. Run `apt-get install cpu-checker && kvm-ok` to verify that KVM has
63 the correct configuration. If it prints the following message, you're good to
64 go:
65
66```
67$ kvm-ok
68INFO: /dev/kvm exists
69KVM acceleration can be used
70```
71
72- **Xvfb**. To run headless tests (for example, on CI servers), Bazel requires
73 the [X virtual framebuffer](https://www.x.org/archive/X11R7.6/doc/man/man1/Xvfb.1.xhtml).
74 Install it by running `apt-get install xvfb`. Verify that `Xvfb` is installed
75 correctly by running `which Xvfb` and ensure that it's installed at
76 `/usr/bin/Xvfb`:
77
78```
79$ which Xvfb
80/usr/bin/Xvfb
81```
82
ahumeskyc789d782021-03-09 15:45:40 -080083- **32-bit Libraries**. Some of the binaries used by the test infrastructure are
84 32-bit, so on 64-bit machines, ensure that 32-bit binaries can be run. For
85 Ubuntu, install these 32-bit libraries:
86
87```
88sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
89```
90
Googler1403a162021-01-22 13:42:50 -080091## Getting started
jingwen2f963272018-04-11 20:18:44 -070092
93Here is a typical target dependency graph of an `android_instrumentation_test`:
94
95![The target dependency graph on an Android instrumentation test](/assets/android_instrumentation_test.png)
96
Googler07dde6a2021-05-21 09:30:32 -070097### BUILD file
jingwen2f963272018-04-11 20:18:44 -070098
99The graph translates into a `BUILD` file like this:
100
101```python
jingwen2f963272018-04-11 20:18:44 -0700102android_instrumentation_test(
103 name = "my_test",
104 test_app = ":my_test_app",
Googlerc38e6672019-04-12 14:55:08 -0700105 target_device = "@android_test_support//tools/android/emulated_devices/generic_phone:android_23_x86",
jingwen2f963272018-04-11 20:18:44 -0700106)
107
108# Test app and library
109android_binary(
110 name = "my_test_app",
111 instruments = ":my_app",
112 manifest = "AndroidTestManifest.xml",
113 deps = [":my_test_lib"],
114 # ...
115)
116
117android_library(
118 name = "my_test_lib",
119 srcs = glob(["javatest/**/*.java"]),
120 deps = [
121 ":my_app_lib",
Jingwen Chen20b544a2019-03-21 12:52:28 -0700122 "@maven//:androidx_test_core",
123 "@maven//:androidx_test_runner",
124 "@maven//:androidx_test_espresso_espresso_core",
jingwen2f963272018-04-11 20:18:44 -0700125 ],
126 # ...
127)
128
129# Target app and library under test
130android_binary(
131 name = "my_app",
132 manifest = "AndroidManifest.xml",
133 deps = [":my_app_lib"],
134 # ...
135)
136
137android_library(
138 name = "my_app_lib",
139 srcs = glob(["java/**/*.java"]),
140 deps = [
Jingwen Chen20b544a2019-03-21 12:52:28 -0700141 "@maven//:androidx_appcompat_appcompat",
142 "@maven//:androidx_annotation_annotation",
jingwen2f963272018-04-11 20:18:44 -0700143 ]
144 # ...
145)
146```
147
148The main attributes of the rule `android_instrumentation_test` are:
149
150- `test_app`: An `android_binary` target. This target contains test code and
151 dependencies like Espresso and UIAutomator. The selected `android_binary`
152 target is required to specify an `instruments` attribute pointing to another
153 `android_binary`, which is the app under test.
154
155- `target_device`: An `android_device` target. This target describes the
156 specifications of the Android emulator which Bazel uses to create, launch and
157 run the tests. See the [section on choosing an Android
158 device](#choosing-an-android_device) for more information.
159
Jingwen Chen20b544a2019-03-21 12:52:28 -0700160The test app's `AndroidManifest.xml` must include [an `<instrumentation>`
161tag](https://developer.android.com/studio/test/#configure_instrumentation_manifest_settings).
jingwen2734ceb2018-08-14 15:32:49 -0700162This tag must specify the attributes for the **package of the target app** and
163the **fully qualified class name of the instrumentation test runner**,
Jingwen Chen20b544a2019-03-21 12:52:28 -0700164`androidx.test.runner.AndroidJUnitRunner`.
jingwen2734ceb2018-08-14 15:32:49 -0700165
166Here is an example `AndroidTestManifest.xml` for the test app:
167
168```xml
169<?xml version="1.0" encoding="UTF-8"?>
170<manifest xmlns:android="http://schemas.android.com/apk/res/android"
171 xmlns:tools="http://schemas.android.com/tools"
172 package="com.example.android.app.test"
173 android:versionCode="1"
174 android:versionName="1.0">
175
176 <instrumentation
Jingwen Chen20b544a2019-03-21 12:52:28 -0700177 android:name="androidx.test.runner.AndroidJUnitRunner"
jingwen2734ceb2018-08-14 15:32:49 -0700178 android:targetPackage="com.example.android.app" />
179
180 <uses-sdk
181 android:minSdkVersion="16"
182 android:targetSdkVersion="27" />
183
184 <application >
185 <!-- ... -->
186 </application>
187</manifest>
188```
189
Googler07dde6a2021-05-21 09:30:32 -0700190### WORKSPACE dependencies
jingwen2f963272018-04-11 20:18:44 -0700191
192In order to use this rule, your project needs to depend on these external
193repositories:
194
195- `@androidsdk`: The Android SDK. Download this through Android Studio.
196
197- `@android_test_support`: Hosts the test runner, emulator launcher, and
Jingwen Chen20b544a2019-03-21 12:52:28 -0700198 `android_device` targets. You can find the [latest release
199 here](https://github.com/android/android-test/releases)
jingwen2f963272018-04-11 20:18:44 -0700200
Jingwen Chen20b544a2019-03-21 12:52:28 -0700201Enable these dependencies by adding the following lines to your `WORKSPACE`
202file:
jingwen2f963272018-04-11 20:18:44 -0700203
204```python
205# Android SDK
206android_sdk_repository(
207 name = "androidsdk",
208 path = "/path/to/sdk", # or set ANDROID_HOME
209)
210
211# Android Test Support
212ATS_COMMIT = "$COMMIT_HASH"
213http_archive(
214 name = "android_test_support",
Alex Humesky88a58912018-10-11 09:50:26 -0700215 strip_prefix = "android-test-%s" % ATS_COMMIT,
jingwenc251ead2018-05-16 15:07:25 -0700216 urls = ["https://github.com/android/android-test/archive/%s.tar.gz" % ATS_COMMIT],
jingwen2f963272018-04-11 20:18:44 -0700217)
218load("@android_test_support//:repo.bzl", "android_test_repositories")
219android_test_repositories()
jingwen2f963272018-04-11 20:18:44 -0700220```
221
Googler1403a162021-01-22 13:42:50 -0800222## Maven dependencies
jingwen2f963272018-04-11 20:18:44 -0700223
Googlera1a29ec2021-02-26 12:19:25 -0800224For managing dependencies on Maven artifacts from repositories, such as [Google
Jingwen Chen20b544a2019-03-21 12:52:28 -0700225Maven](https://maven.google.com) or [Maven Central](https://central.maven.org),
Googlera1a29ec2021-02-26 12:19:25 -0800226you should use a Maven resolver, such as
Jingwen Chen20b544a2019-03-21 12:52:28 -0700227[rules_jvm_external](https://github.com/bazelbuild/rules_jvm_external).
jingwen2f963272018-04-11 20:18:44 -0700228
Googler47849d42021-01-15 17:43:25 -0800229The rest of this page shows how to use `rules_jvm_external` to
Jingwen Chen20b544a2019-03-21 12:52:28 -0700230resolve and fetch dependencies from Maven repositories.
jingwen2f963272018-04-11 20:18:44 -0700231
Googler1403a162021-01-22 13:42:50 -0800232## Choosing an android_device target
jingwen2f963272018-04-11 20:18:44 -0700233
234`android_instrumentation_test.target_device` specifies which Android device to
235run the tests on. These `android_device` targets are defined in
236[`@android_test_support`](https://github.com/google/android-testing-support-library/tree/master/tools/android/emulated_devices).
237
238```python
Googlerc38e6672019-04-12 14:55:08 -0700239$ bazel query --output=build @android_test_support//tools/android/emulated_devices/generic_phone:android_23_x86
jingwen2f963272018-04-11 20:18:44 -0700240# .../external/android_test_support/tools/android/emulated_devices/generic_phone/BUILD:43:1
241android_device(
Googlerc38e6672019-04-12 14:55:08 -0700242 name = "android_23_x86",
jingwen2f963272018-04-11 20:18:44 -0700243 visibility = ["//visibility:public"],
244 tags = ["requires-kvm"],
245 generator_name = "generic_phone",
246 generator_function = "make_device",
247 generator_location = "tools/android/emulated_devices/generic_phone/BUILD:43",
248 vertical_resolution = 800,
249 horizontal_resolution = 480,
250 ram = 2048,
251 screen_density = 240,
252 cache = 32,
253 vm_heap = 256,
Googlerc38e6672019-04-12 14:55:08 -0700254 system_image = "@android_test_support//tools/android/emulated_devices/generic_phone:android_23_x86_images",
255 default_properties = "@android_test_support//tools/android/emulated_devices/generic_phone:_android_23_x86_props",
jingwen2f963272018-04-11 20:18:44 -0700256)
257```
258
259The device target names use this template:
260
261```
262@android_test_support//tools/android/emulated_devices/${device_type}:${system}_${api_level}_x86_qemu2
263```
264
265In order to launch an `android_device`, the `system_image` for the selected API
266level is required. To download the system image, use Android SDK's
267`tools/bin/sdkmanager`. For example, to download the system image for
Googlerc38e6672019-04-12 14:55:08 -0700268`generic_phone:android_23_x86`, run `$sdk/tools/bin/sdkmanager
jingwen2f963272018-04-11 20:18:44 -0700269"system-images;android-23;default;x86"`.
270
271To see the full list of supported `android_device` targets in
272`@android_test_support`, run the following command:
273
274```
275bazel query 'filter("x86_qemu2$", kind(android_device, @android_test_support//tools/android/emulated_devices/...:*))'
276```
277
Googlera1a29ec2021-02-26 12:19:25 -0800278Bazel currently supports x86-based emulators only. For better performance, use
279`QEMU2` `android_device` targets instead of `QEMU` ones.
jingwen2f963272018-04-11 20:18:44 -0700280
Googler1403a162021-01-22 13:42:50 -0800281## Running tests
jingwen2f963272018-04-11 20:18:44 -0700282
jingwen7c70d822019-01-08 15:12:29 -0800283To run tests, add these lines to your project's `<project root>/.bazelrc` file.
jingwen2f963272018-04-11 20:18:44 -0700284
285```
286# Configurations for testing with Bazel
287# Select a configuration by running
Marc Plano-Lesayae361302019-03-18 08:49:46 -0700288# `bazel test //my:target --config={headless, gui, local_device}`
jingwen2f963272018-04-11 20:18:44 -0700289
jingwen7c70d822019-01-08 15:12:29 -0800290# Headless instrumentation tests (No GUI)
Marc Plano-Lesayae361302019-03-18 08:49:46 -0700291test:headless --test_arg=--enable_display=false
jingwen2f963272018-04-11 20:18:44 -0700292
293# Graphical instrumentation tests. Ensure that $DISPLAY is set.
294test:gui --test_env=DISPLAY
295test:gui --test_arg=--enable_display=true
296
297# Testing with a local emulator or device. Ensure that `adb devices` lists the
298# device.
299# Run tests serially.
300test:local_device --test_strategy=exclusive
301# Use the local device broker type, as opposed to WRAPPED_EMULATOR.
302test:local_device --test_arg=--device_broker_type=LOCAL_ADB_SERVER
303# Uncomment and set $device_id if there is more than one connected device.
304# test:local_device --test_arg=--device_serial_number=$device_id
305```
306
307Then, use one of the configurations to run tests:
308
jingwen2f963272018-04-11 20:18:44 -0700309- `bazel test //my/test:target --config=gui`
Marc Plano-Lesayae361302019-03-18 08:49:46 -0700310- `bazel test //my/test:target --config=headless`
jingwen2f963272018-04-11 20:18:44 -0700311- `bazel test //my/test:target --config=local_device`
312
313Use __only one configuration__ or tests will fail.
314
Googler1403a162021-01-22 13:42:50 -0800315### Headless testing
jingwen2f963272018-04-11 20:18:44 -0700316
jingwenb083de82018-04-30 07:53:09 -0700317With `Xvfb`, it is possible to test with emulators without the graphical
318interface, also known as headless testing. To disable the graphical interface
319when running tests, pass the test argument `--enable_display=false` to Bazel:
320
321```
322bazel test //my/test:target --test_arg=--enable_display=false
323```
jingwen2f963272018-04-11 20:18:44 -0700324
Googler1403a162021-01-22 13:42:50 -0800325### GUI testing
jingwen2f963272018-04-11 20:18:44 -0700326
jingwenb083de82018-04-30 07:53:09 -0700327If the `$DISPLAY` environment variable is set, it's possible to enable the
328graphical interface of the emulator while the test is running. To do this, pass
329these test arguments to Bazel:
330
331```
Marc Plano-Lesay61a5fae2021-09-28 11:59:34 -0700332bazel test //my/test:target --test_arg=--enable_display=true --test_env=DISPLAY
jingwenb083de82018-04-30 07:53:09 -0700333```
jingwen2f963272018-04-11 20:18:44 -0700334
Googler1403a162021-01-22 13:42:50 -0800335### Testing with a local emulator or device
jingwen2f963272018-04-11 20:18:44 -0700336
337Bazel also supports testing directly on a locally launched emulator or connected
338device. Pass the flags
339`--test_strategy=exclusive` and
340`--test_arg=--device_broker_type=LOCAL_ADB_SERVER` to enable local testing mode.
341If there is more than one connected device, pass the flag
342`--test_arg=--device_serial_number=$device_id` where `$device_id` is the id of
343the device/emulator listed in `adb devices`.
344
Googler1403a162021-01-22 13:42:50 -0800345## Sample projects
jingwen2f963272018-04-11 20:18:44 -0700346
347If you are looking for canonical project samples, see the [Android testing
348samples](https://github.com/googlesamples/android-testing#experimental-bazel-support)
349for projects using Espresso and UIAutomator.
350
Googler1403a162021-01-22 13:42:50 -0800351## Espresso setup
jingwen8fe80182018-10-01 09:05:05 -0700352
353If you write UI tests with [Espresso](https://developer.android.com/training/testing/espresso/)
354(`androidx.test.espresso`), you can use the following snippets to set up your
355Bazel workspace with the list of commonly used Espresso artifacts and their
356dependencies:
357
358```
359androidx.test.espresso:espresso-core
360androidx.test:rules
361androidx.test:runner
362javax.inject:javax.inject
363org.hamcrest:java-hamcrest
364junit:junit
365```
366
367One way to organize these dependencies is to create a `//:test_deps` shared
368library:
369
370```python
371# In <project root>/BUILD.bazel
372
jingwen8fe80182018-10-01 09:05:05 -0700373java_library(
374 name = "test_deps",
375 visibility = ["//visibility:public"],
376 exports = [
Jingwen Chen20b544a2019-03-21 12:52:28 -0700377 "@maven//:androidx_test_espresso_espresso_core",
378 "@maven//:androidx_test_rules",
379 "@maven//:androidx_test_runner",
380 "@maven//:javax_inject_javax_inject"
381 "@maven//:org_hamcrest_java_hamcrest",
382 "@maven//:junit_junit",
jingwen8fe80182018-10-01 09:05:05 -0700383 ],
384)
385```
386
387Then, add the required dependencies in `<project root>/WORKSPACE`:
388
389
390```python
Jingwen Chen20b544a2019-03-21 12:52:28 -0700391load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
jingwen8fe80182018-10-01 09:05:05 -0700392
jingwenae7629a2019-10-17 10:18:40 -0700393RULES_JVM_EXTERNAL_TAG = "2.8"
394RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad"
jingwen8fe80182018-10-01 09:05:05 -0700395
396http_archive(
Jingwen Chen20b544a2019-03-21 12:52:28 -0700397 name = "rules_jvm_external",
398 strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
399 sha256 = RULES_JVM_EXTERNAL_SHA,
400 url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
jingwen8fe80182018-10-01 09:05:05 -0700401)
402
Jingwen Chen20b544a2019-03-21 12:52:28 -0700403load("@rules_jvm_external//:defs.bzl", "maven_install")
jingwen8fe80182018-10-01 09:05:05 -0700404
Jingwen Chen20b544a2019-03-21 12:52:28 -0700405maven_install(
406 artifacts = [
407 "junit:junit:4.12",
408 "javax.inject:javax.inject:1",
409 "org.hamcrest:java-hamcrest:2.0.0.0"
410 "androidx.test.espresso:espresso-core:3.1.1",
411 "androidx.test:rules:aar:1.1.1",
412 "androidx.test:runner:aar:1.1.1",
413 ],
414 repositories = [
415 "https://maven.google.com",
416 "https://repo1.maven.org/maven2",
417 ],
jingwen8fe80182018-10-01 09:05:05 -0700418)
419```
420
421Finally, in your test `android_binary` target, add the `//:test_deps`
422dependency:
423
424```python
425android_binary(
426 name = "my_test_app",
427 instruments = "//path/to:app",
428 deps = [
429 "//:test_deps",
430 # ...
431 ],
432 # ...
433)
434```
435
Googler1403a162021-01-22 13:42:50 -0800436## Tips
jingwen2f963272018-04-11 20:18:44 -0700437
Googler1403a162021-01-22 13:42:50 -0800438### Reading test logs
jingwen2f963272018-04-11 20:18:44 -0700439
440Use `--test_output=errors` to print logs for failing tests, or
441`--test_output=all` to print all test output. If you're looking for an
442individual test log, go to
443`$PROJECT_ROOT/bazel-testlogs/path/to/InstrumentationTestTargetName`.
444
445For example, the test logs for `BasicSample` canonical project are in
446`bazel-testlogs/ui/espresso/BasicSample/BasicSampleInstrumentationTest`:
447
448```
449$ tree bazel-testlogs/ui/espresso/BasicSample/BasicSampleInstrumentationTest
450.
451├── adb.409923.log
452├── broker_logs
453│   ├── aapt_binary.10.ok.txt
454│   ├── aapt_binary.11.ok.txt
455│   ├── adb.12.ok.txt
456│   ├── adb.13.ok.txt
457│   ├── adb.14.ok.txt
458│   ├── adb.15.fail.txt
459│   ├── adb.16.ok.txt
460│   ├── adb.17.fail.txt
461│   ├── adb.18.ok.txt
462│   ├── adb.19.fail.txt
463│   ├── adb.20.ok.txt
464│   ├── adb.21.ok.txt
465│   ├── adb.22.ok.txt
466│   ├── adb.23.ok.txt
467│   ├── adb.24.fail.txt
468│   ├── adb.25.ok.txt
469│   ├── adb.26.fail.txt
470│   ├── adb.27.ok.txt
471│   ├── adb.28.fail.txt
472│   ├── adb.29.ok.txt
473│   ├── adb.2.ok.txt
474│   ├── adb.30.ok.txt
475│   ├── adb.3.ok.txt
476│   ├── adb.4.ok.txt
477│   ├── adb.5.ok.txt
478│   ├── adb.6.ok.txt
479│   ├── adb.7.ok.txt
480│   ├── adb.8.ok.txt
481│   ├── adb.9.ok.txt
Googlerc38e6672019-04-12 14:55:08 -0700482│   ├── android_23_x86.1.ok.txt
jingwen2f963272018-04-11 20:18:44 -0700483│   └── exec-1
484│   ├── adb-2.txt
485│   ├── emulator-2.txt
486│   └── mksdcard-1.txt
487├── device_logcat
488│   └── logcat1635880625641751077.txt
489├── emulator_itCqtc.log
490├── outputs.zip
491├── pipe.log.txt
492├── telnet_pipe.log.txt
493└── tmpuRh4cy
494 ├── watchdog.err
495 └── watchdog.out
496
4974 directories, 41 files
498```
499
Googler1403a162021-01-22 13:42:50 -0800500### Reading emulator logs
jingwenb083de82018-04-30 07:53:09 -0700501
502The emulator logs for `android_device` targets are stored in the `/tmp/`
503directory with the name `emulator_xxxxx.log`, where `xxxxx` is a
504randomly-generated sequence of characters.
505
506Use this command to find the latest emulator log:
507
508```
509ls -1t /tmp/emulator_*.log | head -n 1
510```
511
Googler1403a162021-01-22 13:42:50 -0800512### Testing against multiple API levels
jingwen2f963272018-04-11 20:18:44 -0700513
514If you would like to test against multiple API levels, you can use a list
515comprehension to create test targets for each API level. For example:
516
517```python
518API_LEVELS = [
519 "19",
520 "20",
521 "21",
522 "22",
523]
524
525[android_instrumentation_test(
526 name = "my_test_%s" % API_LEVEL,
527 test_app = ":my_test_app",
528 target_device = "@android_test_support//tools/android/emulated_devices/generic_phone:android_%s_x86_qemu2" % API_LEVEL,
529) for API_LEVEL in API_LEVELS]
530```
531
Googler1403a162021-01-22 13:42:50 -0800532## Known issues
jingwen2f963272018-04-11 20:18:44 -0700533
534- [Forked adb server processes are not terminated after
535 tests](https://github.com/bazelbuild/bazel/issues/4853)
jingwen2f963272018-04-11 20:18:44 -0700536- While APK building works on all platforms (Linux, macOS, Windows), testing
537 only works on Linux.
538- Even with `--config=local_adb`, users still need to specify
539 `android_instrumentation_test.target_device`.
540- If using a local device or emulator, Bazel does not uninstall the APKs after
541 the test. Clean the packages by running this command: `adb shell pm list
542 packages com.example.android.testing | cut -d ':' -f 2 | tr -d '\r' | xargs
543 -L1 -t adb uninstall`