Bazel Android Team
Test project: https://github.com/googlesamples/android-testing
Tested with Bazel version 0.12.0rc2
Tested on fresh GCE Ubuntu 14.04 and 16.04 images with nested KVM support
$ git clone https://github.com/googlesamples/android-testing
$ sudo apt-get install -y maven xvfb qemu-system-x86 unzip cpu-checker
$ wget [https://releases.bazel.build/0.12.0/rc2/bazel-0.12.0rc2-installer-linux-x86_64.sh](https://releases.bazel.build/0.12.0/rc2/bazel-0.12.0rc2-installer-linux-x86_64.sh)
$ chmod u+x bazel-0.12.0rc2-installer-linux-x86_64.sh
$ ./bazel-0.12.0rc2-installer-linux-x86_64.sh --user
$ echo "source $HOME/.bazel/bin/bazel-complete.bash" >> ~/.bashrc
$ echo "export PATH=\"$HOME/bin:$PATH\"" >> ~/.bashrc
$ source ~/.bashrc
$ bazel version # verify Bazel version
$ wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
$ unzip -d sdk sdk-tools-linux-3859397.zip
$ cd sdk
$ yes | tools/bin/sdkmanager --licenses # accept license
$ tools/bin/sdkmanager --update
$ tools/bin/sdkmanager "emulator" "system-images;android-23;default;x86" "platform-tools" "build-tools;27.0.3" "platforms;android-27" # test project only uses system images on api 23.
$ kvm-ok
$ sudo groupadd kvm
$ sudo usermod -a -G kvm $(whoami)
$ sudo chown root:kvm /dev/kvm
$ echo 'KERNEL=="kvm", NAME="%k", GROUP="kvm", MODE="0660"' | sudo tee --append /etc/udev/rules.d/65-kvm.rules
$ sudo reboot
$ cd ~/android-testing
# remove path attribute from android_sdk_repository in WORKSPACE
$ export ANDROID_HOME=$HOME/sdk
$ bazel test //... --spawn_strategy=local
INFO: Analysed 46 targets (0 packages loaded).
INFO: Found 37 targets and 9 test targets...
[1 / 10] 9 actions running
Testing //ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest; 71s local
INFO: Elapsed time: 103.926s, Critical Path: 103.61s
INFO: Build completed successfully, 10 total actions
//ui/espresso/BasicSample:BasicSampleInstrumentationTest PASSED in 84.7s
//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest PASSED in 95.0s
//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest PASSED in 91.4s
//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest PASSED in 83.2s
//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest PASSED in 79.0s
//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest PASSED in 83.3s
//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest PASSED in 90.0s
//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest PASSED in 84.8s
//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest PASSED in 103.6s</td>
-
If emulator dies or unified launcher throws an error, Bazel doesn’t print the emulator log to the stdout. The emulator and unified launcher logs can be found in /tmp.
-
Headless testing requires --spawn_strategy=local.