name | Name; required A unique name for this target. |
deps | List of labels; default is [] The list of other libraries to be linked in to the binary target. Permitted library types are: android_library, java_library with android constraint and cc_library wrapping or producing .so native libraries for the Android target platform. |
srcs | List of labels; default is [] The list of source files that are processed to create the target. srcs files of type .java are compiled. For readability’s sake, it is not good to put the name of a generated .java source file into the srcs. Instead, put the depended-on rule name in the srcs, as described below. srcs files of type .srcjar are unpacked and compiled. (This is useful if you need to generate a set of .java files with a genrule or build extension.) |
assets | List of labels; default is [] The list of assets to be packaged. This is typically a glob of all files under the assets directory. You can also reference other rules (any rule that produces files) or exported files in the other packages, as long as all those files are under the assets_dir directory in the corresponding package. |
assets_dir | String; default is "" The string giving the path to the files in assets. The pair assets and assets_dir describe packaged assets and either both attributes should be provided or none of them. |
crunch_png | Boolean; default is True Do PNG crunching (or not). This is independent of nine-patch processing, which is always done. This is a deprecated workaround for an aapt bug which has been fixed in aapt2. |
custom_package | String; default is "" Java package for which java sources will be generated. By default the package is inferred from the directory where the BUILD file containing the rule is. You can specify a different package but this is highly discouraged since it can introduce classpath conflicts with other libraries that will only be detected at runtime. |
debug_key | Label; default is "@bazel_tools//tools/android:debug_keystore" File containing the debug keystore to be used to sign the debug apk. Usually you do not want to use a key other than the default key, so this attribute should be omitted. WARNING: Do not use your production keys, they should be strictly safeguarded and not kept in your source tree. |
debug_signing_keys | List of labels; default is [] List of files, debug keystores to be used to sign the debug apk. Usually you do not want to use keys other than the default key, so this attribute should be omitted. WARNING: Do not use your production keys, they should be strictly safeguarded and not kept in your source tree. |
debug_signing_lineage_file | Label; default is None File containing the signing lineage for the debug_signing_keys. Usually you do not want to use keys other than the default key, so this attribute should be omitted. WARNING: Do not use your production keys, they should be strictly safeguarded and not kept in your source tree. |
densities | List of strings; default is [] Densities to filter for when building the apk. This will strip out raster drawable resources that would not be loaded by a device with the specified screen densities, to reduce APK size. A corresponding compatible-screens section will also be added to the manifest if it does not already contain a superset listing. |
dex_shards | Integer; default is 1 Number of shards dexing should be decomposed into. This is makes dexing much faster at the expense of app installation and startup time. The larger the binary, the more shards should be used. 25 is a good value to start experimenting with. Note that each shard will result in at least one dex in the final app. For this reason, setting this to more than 1 is not recommended for release binaries. |
dexopts | List of strings; default is [] Additional command-line flags for the dx tool when generating classes.dex. Subject to “Make variable” substitution and Bourne shell tokenization. |
enable_data_binding | Boolean; default is False If true, this rule processes data binding expressions in layout resources included through the resource_files attribute. Without this setting, data binding expressions produce build failures. To build an Android app with data binding, you must also do the following: 1. Set this attribute for all Android rules that transitively depend on this one. This is because dependers inherit the rule’s data binding expressions through resource merging. So they also need to build with data binding to parse those expressions.- Add a deps = entry for the data binding runtime library to all targets that set this attribute. The location of this library depends on your depot setup. |
incremental_dexing | Integer; nonconfigurable; default is -1 Force the target to be built with or without incremental dexing, overriding defaults and —incremental_dexing flag. |
instruments | Label; default is None The android_binary target to instrument. If this attribute is set, this android_binary will be treated as a test application for instrumentation tests. An android_instrumentation_test target can then specify this target in its test_app attribute. |
javacopts | List of strings; default is [] Extra compiler options for this target. Subject to “Make variable” substitution and Bourne shell tokenization. These compiler options are passed to javac after the global compiler options. |
key_rotation_min_sdk | String; default is "" Sets the minimum Android platform version (API Level) for which an APK’s rotated signing key should be used to produce the APK’s signature. The original signing key for the APK will be used for all previous platform versions. |
main_dex_list | Label; default is None A text file contains a list of class file names. Classes defined by those class files are put in the primary classes.dex. e.g.: android/support/multidex/MultiDex$V19.class android/support/multidex/MultiDex.class android/support/multidex/MultiDexApplication.class com/google/common/base/Objects.class Must be used with multidex="manual_main_dex". |
main_dex_list_opts | List of strings; default is [] Command line options to pass to the main dex list builder. Use this option to affect the classes included in the main dex list. |
main_dex_proguard_specs | List of labels; default is [] Files to be used as the Proguard specifications to determine classes that must be kept in the main dex. Only allowed if the multidex attribute is set to legacy. |
manifest | Label; required The name of the Android manifest file, normally AndroidManifest.xml. Must be defined if resource_files or assets are defined. |
manifest_values | Dictionary: String -> String; default is {} A dictionary of values to be overridden in the manifest. Any instance of ${name} in the manifest will be replaced with the value corresponding to name in this dictionary. applicationId, versionCode, versionName, minSdkVersion, targetSdkVersion and maxSdkVersion will also override the corresponding attributes in the manifest and uses-sdk tags. packageName will be ignored and will be set from either applicationId if specified or the package in manifest. When manifest_merger is set to legacy, only applicationId, versionCode and versionName will have any effect. |
multidex | String; default is "native" Whether to split code into multiple dex files. Possible values: * native: Split code into multiple dex files when the dex 64K index limit is exceeded. Assumes native platform support for loading multidex classes at runtime. This works with only Android L and newer. * legacy: Split code into multiple dex files when the dex 64K index limit is exceeded. Assumes multidex classes are loaded through application code (i.e. no native platform support). * manual_main_dex: Split code into multiple dex files when the dex 64K index limit is exceeded. The content of the main dex file needs to be specified by providing a list of classes in a text file using the main_dex_list attribute. * off: Compile all code to a single dex file, even if it exceeds the index limit. |
nocompress_extensions | List of strings; default is [] A list of file extension to leave uncompressed in apk. |
package_id | Integer; default is 0 Package ID to be assigned to resources in this binary. See AAPT2’s --package-id argument for more information. This can (and should) typically be left unset, resulting in the default value of 127 (0x7F). |
plugins | List of labels; default is [] Java compiler plugins to run at compile-time. Every java_plugin specified in the plugins attribute will be run whenever this target is built. Resources generated by the plugin will be included in the result jar of the target. |
proguard_apply_dictionary | Label; default is None File to be used as a mapping for proguard. A line separated file of “words” to pull from when renaming classes and members during obfuscation. |
proguard_apply_mapping | Label; default is None File to be used as a mapping for proguard. A mapping file generated by proguard_generate_mapping to be re-used to apply the same mapping to a new build. |
proguard_generate_mapping | Boolean; nonconfigurable; default is False Whether to generate Proguard mapping file. The mapping file will be generated only if proguard_specs is specified. This file will list the mapping between the original and obfuscated class, method, and field names. WARNING: If this attribute is used, the Proguard specification should contain neither -dontobfuscate nor -printmapping. |
proguard_specs | List of labels; default is [] Files to be used as Proguard specification. This file will describe the set of specifications to be used by Proguard. |
resource_configuration_filters | List of strings; default is [] A list of resource configuration filters, such ‘en’ that will limit the resources in the apk to only the ones in the ‘en’ configuration. To enable pseudolocalization, include the en_XA and/or ar_XB pseudo-locales. |
resource_files | List of labels; default is [] The list of resources to be packaged. This is typically a glob of all files under the res directory. Generated files (from genrules) can be referenced by Label here as well. The only restriction is that the generated outputs must be under the same “res” directory as any other resource files that are included. |
shrink_resources | Integer; default is -1 Whether to perform resource shrinking. Resources that are not used by the binary will be removed from the APK. This is only supported for rules using local resources (i.e. the manifest and resource_files attributes) and requires ProGuard. It operates in mostly the same manner as the Gradle resource shrinker (https://developer.android.com/studio/build/shrink-code.html#shrink-resources). Notable differences: * resources in values/ will be removed as well as file based resources * uses strict mode by default * removing unused ID resources is only supported with aapt2 If resource shrinking is enabled, name_files/resource_shrinker.log will also be generated, detailing the analysis and deletions performed. Possible values: * shrink_resources = 1: Turns on Android resource shrinking * shrink_resources = 0: Turns off Android resource shrinking * shrink_resources = -1: Shrinking is controlled by the —android_resource_shrinking flag. |