Sample codes for running cc_test on Android devices.
cd sample
#launch android emulator
$ANDROID_HOME/emulator/emulator -avd {AVDNAME}
bazel run \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=x86_64 \
//:gtest_samples_android \
-- \
--gtest_color=yes
Include rules to WORKSPACE
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
android_sdk_repository(
name = "androidsdk",
api_level = 28,
)
android_ndk_repository(
name = "androidndk"
)
git_repository(
name = "rules_android_cc_test",
remote = "https://github.com/yrom/rules_android_cc_test.git",
branch = "main",
)
Declares cc_test
target in BUILD
:
load("@rules_android_cc_test//:defs.bzl", "cc_test")
cc_test(
name = "samples",
size = "small",
srcs = []
)
...it will auto declares android target suffix with _android
: //:samples_android
bazel query //:all
#//:samples
#//:samples_android
#Loading: 0 packages loaded
Run cc_test on Android:
bazel run \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=<abi> \
//:samples_android \
-- \
[options]