Skip to main content

android_instrumentation_apk

name

def name(
*,
name: str,
default_target_platform: None | str = ...,
target_compatible_with: list[str] = ...,
compatible_with: list[str] = ...,
exec_compatible_with: list[str] = ...,
visibility: list[str] = ...,
within_view: list[str] = ...,
metadata: OpaqueMetadata = ...,
tests: list[str] = ...,
modifiers: OpaqueMetadata = ...,
_android_toolchain: str = ...,
_apple_platforms: dict[str, str] = ...,
_dex_toolchain: str = ...,
_exec_os_type: str = ...,
_is_building_android_binary: bool = ...,
_is_force_single_cpu: bool = ...,
_is_force_single_default_cpu: bool = ...,
_java_toolchain: str = ...,
apk: str,
contacts: list[str] = ...,
cpu_filters: list[str] = ...,
default_host_platform: None | str = ...,
deps: list[str] = ...,
disable_pre_dex: bool = ...,
enable_bootstrap_dexes: bool = ...,
includes_vector_drawables: bool = ...,
is_self_instrumenting: bool = ...,
labels: list[str] = ...,
licenses: list[str] = ...,
manifest: None | str = ...,
manifest_skeleton: None | str = ...,
min_sdk_version: None | int = ...,
native_library_merge_map: None | dict[str, list[str]] = ...,
native_library_merge_sequence: None | list = ...,
preprocess_java_classes_bash: None | str = ...,
preprocess_java_classes_cmd: None | str = ...,
preprocess_java_classes_deps: list[str] = ...,
primary_dex_patterns: list[str] = ...,
use_split_dex: None | bool = ...,
) -> None

An android_instrumentation_apk() rule is used to generate an Android Instrumentation APK.

Parameters

  • name: name of the target
  • default_target_platform: specifies the default target platform, used when no platforms are specified on the command line
  • target_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • exec_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
  • visibility: a list of visibility patterns restricting what targets can depend on this one
  • within_view: a list of visibility patterns restricting what this target can depend on
  • metadata: a key-value map of metadata associated with this target
  • tests: a list of targets that provide tests for this one
  • modifiers: an array of modifiers associated with this target

Details

Android's Testing Fundamentals documentation includes a diagram that shows the relationship between an "application package" and a "test package" when running a test. This rule corresponds to a test package. Note that a test package has an interesting quirk where it is compiled against an application package, but must not include the resources or Java classes of the application package. Therefore, this class takes responsibility for making sure the appropriate bits are excluded. Failing to do so will generate mysterious runtime errors when running the test.

Examples:

Here is an example of an android_instrumentation_apk() rule that tests an android_binary(), and depends on a test package.


android_library(
name = 'test',
srcs = glob(['test/**/*.java']),
)

android_binary(
name = 'messenger',
manifest = 'AndroidManifest.xml',
keystore = '//keystores:prod',
package_type = 'release',
proguard_config = 'proguard.cfg',
deps = [
...
],
)

# Building this rule will produce a file named messenger_test.apk
android_instrumentation_apk(
name = 'messenger_test',
manifest = 'AndroidInstrumentationManifest.xml',
apk = ':messenger',
deps = [
':test',
],
)