Buck: android_instrumentation_apk()
Support Ukraine. Help Provide Humanitarian Aid to Ukraine.

android_instrumentation_apk()

This is liable to change in the future.

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

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.

Arguments

  • name (required) #

    The short name for this build target. Also, the name of the APK generated from this target.

  • manifest (defaults to None) #

    Relative path to the Android manifest for the APK. The common case is that the manifest will be in the same directory as the rule, in which case this will simply be 'AndroidManifest.xml', but it can also reference an android_manifest rule. Prefer using manifest_skeleton, which performs merging automatically. Exactly one of manifest and manifest_skeleton must be set.

  • manifest_skeleton (defaults to None) #

    Relative path to the skeleton Android manifest for the APK. An android_manifest will be created automatically to merge all manifests from libraries and resources going into the app. The common case is that the manifest will be in the same directory as the rule, in which case this will simply be 'AndroidManifest.xml'. Exactly one of manifest and manifest_skeleton must be set.

  • apk (required) #

    APK build target, which should be used for the instrumentation APK. Can be either a android_binary or a apk_genrule.

  • deps (defaults to []) #

    List of build targets whose corresponding compiled Java code, Android resources, and native libraries will be included in the APK. From the transitive closure of these dependencies, the outputs of rules of the following type will be included in the APK:

    • android_library()
    • android_resource()
    • cxx_library()
    • groovy_library()
    • java_library()
    • java_binary()
    • prebuilt_jar()
    • ndk_library()
    • prebuilt_native_library()

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their deps or exported_deps attributes. For more information, see visibility.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter().

Examples

Here is an example of an android_instrumentation_apk() rule that tests a 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',
  ],
)