android_library()
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 short name for this build target.
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 toNone
) #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 toNone
) #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.
skip_non_union_r_dot_java
(defaults tofalse
) #When using
resource_union_package
settingskip_non_union_r_dot_java
will skip generating dummy R.java for other packages which are unnecessary. Reducing the number of R.java helps in improving the overall compile time especially in libraries with large number of dependent prebuilt targets.deps
(defaults to[]
) #Rules (usually other
android_library
rules) that are used to generate the classpath required to compile thisandroid_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
.free_compiler_args
(defaults to[]
) #List of additional arguments to pass into the Kotlin compiler.
annotation_processing_tool
(defaults tokapt
) #Specifies the tool to use for annotation processing. Possible values: "kapt" or "javac". "kapt" allows running Java annotation processors against Kotlin sources while backporting it for Java sources too. "javac" works only against Java sources, Kotlin sources won't have access to generated classes at compile time.
kapt_ap_options
(required) #Map of annotation processor options to pass into kapt via the apoptions plugin option. Each entry should be a key value pair of the processor option and its value. Default is an empty map. E.g. kapt_ap_options = { 'someAnnotationOption': 'someValue' } More information here: https://kotlinlang.org/docs/reference/kapt.html
exported_deps
(defaults to[]
) #Other
android_library
rules that depend on this rule will also include itsexported_deps
in their classpaths. This is useful when the public API of a rule has return types or checked exceptions that are defined in another rule, which would otherwise require callers to add an extra dependency. It's also useful for exposing e.g. a collection ofprebuilt_jar
rules as a single target for callers to depend on. Targets inexported_deps
are implicitly included in thedeps
of this rule, so they don't need to be repeated there.provided_deps
(defaults to[]
) #These represent dependencies that are known to be provided at run time, but are required in order for the code to compile. Examples of
provided_deps
include the JEE servlet APIs. When this rule is included in aandroid_binary
, theprovided_deps
will not be packaged into the output.exported_provided_deps
(defaults to[]
) #This is a combination of
provided_deps
andexported_deps
. Rules listed in this parameter will be added to classpath of rules that depend on this rule, but they will not be included in a binary if binary depends on a such target.deps_query
(defaults toNone
) #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
$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 declaresandroid_library( name = 'lib', deps = ['//foo:foo'], deps_query = '$declared_deps', )
then the macro$declared_deps
would be expanded to a literalset(//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 toNone
) #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.abi_generation_mode
(defaults toNone
) #Overrides
[java].abi_generation_mode
for this rule.source_only_abi_deps
(defaults to[]
) #These are dependencies that must be present during source-only ABI generation. Typically such dependencies are added when some property of the code in this rule prevents source-only ABI generation from being correct without these dependencies being present.
Having
source_only_abi_deps
prevents Buck from completely flattening the build graph, thus reducing the performance win from source-only ABI generation. They should be avoided when possible. Often only a small code change is needed to avoid them. For more information on such code changes, read about source-only ABI generation.required_for_source_only_abi
(defaults toFalse
) #Indicates that this rule must be present on the classpath during source-only ABI generation of any rule that depends on it. Typically this is done when a rule contains annotations, enums, constants, or interfaces.
Having rules present on the classpath during source-only ABI generation prevents Buck from completely flattening the build graph, thus reducing the performance win from source-only ABI generation. These rules should be kept small (ideally just containing annotations, constants, enums, and interfaces) and with minimal dependencies of their own.
tests
(defaults to[]
) #List of build targets that identify tests that exercise this target.
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
orexported_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
Anandroid_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.htmlandroid_resource( name = 'res', res = 'res', package = 'com.example', ) android_library( name = 'my_library', srcs = glob(['src/**/*.java']), deps = [ ':res', ], )