Buck: android_library()

android_library()

An android_library() rule is used to define a set of Java files that can be compiled together against the Android SDK. The main output of an android_library() rule is a single JAR file containing all of the compiled class files and resources.

Arguments

  • name (required) #

    The name of the rule.

  • srcs (defaults to []) #

    The set of .java files to compile for this rule.

  • resources (defaults to []) #

    Static files to include among the compiled .class files. These files can be loaded via Class.getResource().

    Note: Buck uses the src_roots property in .buckconfig to help determine where resources should be placed within the generated JAR file.

  • manifest (defaults to None) #

    An optional Android Manifest for the library to declare any permissions or intents it may need or want to handle. May either be a file or a android_manifest target.

  • final_r_name (defaults to None) #

    An optional name for a class like R.java with final values that is generated to be used for annotation processors. The values will be wrong i.e they will not match the real values in the final android binary, so they should only be used by carefully crafted annotation processors.

  • deps (defaults to []) #

    Rules (usually other android_library rules) that are used to generate the classpath required to compile this android_library.

  • source (defaults to <global value>) #

    Specifies the version of Java (as a string) to interpret source files as. Overrides the value in "source_level" in the "java" section of .buckconfig.

  • target (defaults to <global value>) #

    Specifies the version of Java (as a string) for which to generate code. Overrides the value in "target_level" in the "java" section of .buckconfig.

  • javac (defaults to <global value>) #

    Specifies the Java compiler program to use for this rule. The value is a source path (e.g., Only one of "javac" and "javac_jar" may be set for a given rule. Overrides the value in "javac" in the "tools" section of .buckconfig.

  • javac_jar (defaults to <global value>) #

    Specifies the Java compiler program to use for this rule. The value is a source path (e.g., Only one of "javac_jar" and "javac" may be set for a given rule. Overrides the value in "javac_jar" in the "tools" section of .buckconfig.

  • compiler_class_name (defaults to <global value>) #

    Specifies the Java compiler class name to use in tandem with javac_jar. Overrides the value in .buckconfig.

  • extra_arguments (defaults to []) #

    List of additional arguments to pass into the Java compiler. These arguments follow the ones specified in .buckconfig.

  • extra_kotlinc_arguments (defaults to []) #

    List of additional arguments to pass into the Kotlin compiler.

  • exported_deps (defaults to []) #

    This is the same as in java_library.

  • deps_query (defaults to None) #

    Status: experimental/unstable. The deps query takes a query string that accepts the following query functions, and appends the output of the query to the declared deps:

    • attrfilter
    • deps
    • except
    • intersect
    • filter
    • kind
    • set
    • union
    The macro $declared_deps may be used anywhere a target literal pattern is expected in order to refer to the explicit deps of this rule as they appear in the rule's definition. For example, if your build rule declares
      android_library(
        name = 'lib',
        deps = ['//foo:foo'],
        deps_query = '$declared_deps',
      )
    then the macro $declared_deps would be expanded to a literal set(//foo:foo). Some example queries:
      "filter({name_regex}, $declared_deps)".format(name_regex='//.*')
      "attrfilter(annotation_processors, com.foo.Processor, $declared_deps)"

  • provided_deps_query (defaults to None) #

    Status: experimental/unstable. The provided deps query functions in the same way as the deps query, but the referenced deps using $declared are the provided deps of the target, and the results of the query are appended to the declared provided deps.

  • tests (defaults to []) #

    List of build targets that identify the test rules that exercise this target.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule in its deps.

  • 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

An android_library rule used in concert with an android_resource rule. This would be a common arrangement for a standard Android Library project as defined by http://developer.android.com/tools/projects/index.html
android_resource(
  name = 'res',
  res = 'res',
  package = 'com.example',
)

android_library(
  name = 'my_library',
  srcs = glob(['src/**/*.java']),
  deps = [
    ':res',
  ],
)