android_data

Utilities for working with Android data (manifests, resources, and assets). This API is non-final and subject to change without warning; do not rely on it.

assets_from_deps

AndroidAssetsInfo android_data.assets_from_deps(deps=[], neverlink=False)

Creates an AndroidAssetsInfoApi from this target's asset dependencies, ignoring local assets. No processing will be done. This method is deprecated and exposed only for backwards-compatibility with existing behavior.

Parameters

Parameter Description
deps

sequence of AndroidAssetsInfos

Dependencies to inherit assets from.

bool

Defaults to False. If true, assets will not be exposed to targets that depend on them.

make_aar

AndroidLibraryAarInfo android_data.make_aar(ctx, resource_info, asset_info, library_class_jar, *, proguard_specs=[], deps=[], neverlink=False)

Builds an AAR and corresponding provider for this target. The resource and asset providers from this same target must both be passed, as must the class JAR output of building the Android Java library.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

resource_info

AndroidResourcesInfo

The provider containing processed resources for this target, produced, for example, by merge_resources.

asset_info

AndroidAssetsInfo

The provider containing processed assets for this target, produced, for example, by merge_assets.

library_class_jar

File

The library class jar.

proguard_specs

sequence of Targets

Files to be used as Proguard specification for this target, which will be inherited in the top-level target.

deps

sequence of AndroidLibraryAarInfos

Dependant AAR providers used to build this AAR.

bool

Defaults to False. If true, this target's Aar will not be generated or propagated to targets that depend upon it.

make_binary_settings

AndroidBinaryDataSettings android_data.make_binary_settings(ctx, *, shrink_resources=None, resource_configuration_filters=[], densities=[], nocompress_extensions=[], aapt_version='auto')

Returns a wrapper object containing various settings shared across multiple methods for processing binary data.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

shrink_resources

bool

Whether to shrink resources. Defaults to the value used in Android configuration.

resource_configuration_filters

sequence of strings

A SkylarkList of resource configuration filters, such 'en' that will limit the resources in the apk to only the ones in the 'en' configuration.

densities

sequence of strings

Densities to filter for when building the apk. A corresponding compatible-screens section will also be added to the manifest if it does not already contain a superset SkylarkListing.

nocompress_extensions

sequence of strings

A SkylarkList of file extension to leave uncompressed in apk. Templates must be expanded before passing this value in.

aapt_version

string

The version of aapt to use. Defaults to 'auto'. 'aapt' and 'aapt2' are also supported.

merge_assets

AndroidAssetsInfo android_data.merge_assets(ctx, *, assets=None, assets_dir=None, deps=[], neverlink=False)

Merges this target's assets together with assets inherited from dependencies. Note that, by default, actions for validating the merge are created but may not be called. You may want to force these actions to be called - see the 'validation_result' field in AndroidAssetsInfoApi

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

assets

sequence of Targets

Targets containing raw assets for this target. If passed, 'assets_dir' must also be passed.

assets_dir

string

Directory the assets are contained in. Must be passed if and only if 'assets' is passed. This path will be split off of the asset paths on the device.

deps

sequence of AndroidAssetsInfos

Providers containing assets from dependencies. These assets will be merged together with each other and this target's assets.

bool

Defaults to False. If passed as True, these assets will not be inherited by targets that depend on this one.

merge_resources

dict android_data.merge_resources(ctx, manifest, *, resources=[], deps=[], neverlink=False, enable_data_binding=False)

Merges this target's resources together with resources inherited from dependencies. Returns a dict of provider type to actual info, with elements for AndroidResourcesInfoApi (various resource information) and JavaInfoApi (wrapping the R.class jar, for use in Java compilation). The passed manifest provider is used to get Android package information and to validate that all resources it refers to are available. Note that this method might do additional processing to this manifest, so in the future, you may want to use the manifest contained in this method's output instead of this one.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

manifest

AndroidManifestInfo

The provider of this target's manifest. This provider is produced by, for example, stamp_android_manifest.

resources

sequence of file_providers

Providers of this target's resources.

deps

sequence of AndroidResourcesInfos

Targets containing raw resources from dependencies. These resources will be merged together with each other and this target's resources.

bool

Defaults to False. If passed as True, these resources will not be inherited by targets that depend on this one.

enable_data_binding

bool

Defaults to False. If True, processes data binding expressions in layout resources.

process_aar_import_data

dict android_data.process_aar_import_data(ctx, resource, assets, manifest, *, deps=[])

Processes assets, resources, and manifest for aar_import targets

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

resource

File

The resouce file.

assets

File

The assets file.

manifest

File

The manifest file.

deps

sequence of Targets

Targets to inherit asset and resource dependencies from.

process_binary_data

AndroidBinaryData android_data.process_binary_data(ctx, *, resources=[], assets=None, assets_dir=None, manifest=None, custom_package=None, manifest_values={}, deps=[], manifest_merger='auto', binary_settings=None, crunch_png=True, enable_data_binding=False)

Processes resources, assets, and manifests for android_binary and returns the appropriate providers.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

resources

sequence of file_providers

Providers of this target's resources.

assets

sequence of Targets

Targets containing raw assets for this target. If passed, 'assets_dir' must also be passed.

assets_dir

string

Directory the assets are contained in. Must be passed if and only if 'assets' is passed. This path will be split off of the asset paths on the device.

manifest

File

If passed, the manifest to use for this target. Otherwise, a dummy manifest will be generated.

custom_package

string

The Android application package to stamp the manifest with. If not provided, the current Java package, derived from the location of this target's BUILD file, will be used. For example, given a BUILD file in 'java/com/foo/bar/BUILD', the package would be 'com.foo.bar'.

manifest_values

dict of strings

A dictionary of values to be overridden in the manifest. You must expand any templates in the values before calling this function.

deps

sequence of Targets

Dependency targets. Providers will be extracted from these dependencies for each type of data.

manifest_merger

string

The manifest merger to use. Defaults to 'auto', but 'android' and 'legacy' are also supported.

binary_settings

AndroidBinaryDataSettings

Settings common to various binary processing methods, created with make_binary_data_settings.

crunch_png

bool

Whether PNG crunching should be done. Defaults to True.

enable_data_binding

bool

Defaults to False. If True, processes data binding expressions in layout resources.

process_library_data

dict android_data.process_library_data(ctx, library_class_jar, *, manifest=None, resources=None, assets=None, assets_dir=None, exports_manifest=None, custom_package=None, neverlink=False, enable_data_binding=False, proguard_specs=[], deps=[])

Performs full processing of data for android_library or similar rules. Returns a dict from provider type to providers for the target.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

library_class_jar

File

The library class jar.

manifest

File

If passed, the manifest to use for this target. Otherwise, a dummy manifest will be generated.

resources

sequence of file_providers

Providers of this target's resources.

assets

sequence of Targets

Targets containing raw assets for this target. If passed, 'assets_dir' must also be passed.

assets_dir

string

Directory the assets are contained in. Must be passed if and only if 'assets' is passed. This path will be split off of the asset paths on the device.

exports_manifest

bool

Defaults to False. If passed as True, this manifest will be exported to and eventually merged into targets that depend on it. Otherwise, it won't be inherited.

custom_package

string

The Android application package to stamp the manifest with. If not provided, the current Java package, derived from the location of this target's BUILD file, will be used. For example, given a BUILD file in 'java/com/foo/bar/BUILD', the package would be 'com.foo.bar'.

bool

Defaults to False. If passed as True, these resources and assets will not be inherited by targets that depend on this one.

enable_data_binding

bool

Defaults to False. If True, processes data binding expressions in layout resources.

proguard_specs

sequence of Targets

Files to be used as Proguard specification for this target, which will be inherited in the top-level target.

deps

sequence of AndroidAssetsInfos

Dependency targets. Providers will be extracted from these dependencies for each type of data.

process_local_test_data

dict android_data.process_local_test_data(ctx, *, manifest=None, resources=[], assets=None, assets_dir=None, custom_package=None, aapt_version='auto', manifest_values={}, deps=[])

Processes resources, assets, and manifests for android_local_test and returns a dict from provider type to the appropriate provider.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

manifest

File

If passed, the manifest to use for this target. Otherwise, a dummy manifest will be generated.

resources

sequence of file_providers

Providers of this target's resources.

assets

sequence of Targets

Targets containing raw assets for this target. If passed, 'assets_dir' must also be passed.

assets_dir

string

Directory the assets are contained in. Must be passed if and only if 'assets' is passed. This path will be split off of the asset paths on the device.

custom_package

string

The Android application package to stamp the manifest with. If not provided, the current Java package, derived from the location of this target's BUILD file, will be used. For example, given a BUILD file in 'java/com/foo/bar/BUILD', the package would be 'com.foo.bar'.

aapt_version

string

The version of aapt to use. Defaults to 'auto'. 'aapt' and 'aapt2' are also supported.

manifest_values

dict of strings

A dictionary of values to be overridden in the manifest. You must expand any templates in these values before they are passed to this function.

deps

sequence of Targets

Dependency targets. Providers will be extracted from these dependencies for each type of data.

resources_from_deps

AndroidResourcesInfo android_data.resources_from_deps(ctx, *, deps=[], neverlink=False, custom_package=None)

Creates an AndroidResourcesInfoApi from this target's resource dependencies, ignoring local resources. Only processing of deps will be done. This method is deprecated and exposed only for backwards-compatibility with existing behavior. An empty manifest will be generated and included in the provider - this path should not be used when an explicit manifest is specified.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

deps

sequence of AndroidResourcesInfos

Dependencies to inherit resources from.

bool

Defaults to False. If true, resources will not be exposed to targets that depend on them.

custom_package

string

The Android application package to stamp the manifest with. If not provided, the current Java package, derived from the location of this target's BUILD file, will be used. For example, given a BUILD file in 'java/com/foo/bar/BUILD', the package would be 'com.foo.bar'.

shrink_data_apk

AndroidBinaryData android_data.shrink_data_apk(ctx, binary_data_info, proguard_output_jar, proguard_mapping, *, binary_settings=None, deps=[], proguard_specs=[], extra_proguard_specs,=[])

Possibly shrinks the data APK by removing resources that were marked as unused during proguarding.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

binary_data_info

AndroidBinaryData

The Info about the binary to shrink, as produced by process_binary_data.

proguard_output_jar

File

The proguard jar output file.

proguard_mapping

File

The proguard mapping output file.

binary_settings

AndroidBinaryDataSettings

Settings common to various binary processing methods, created with make_binary_data_settings.

deps

sequence of Targets

Dependency targets. Providers will be extracted from these dependencies for each type of data.

proguard_specs

sequence of Targets

Files to be used as Proguard specification for this target, which will be inherited in the top-level target.

extra_proguard_specs,

sequence of Targets

Additional proguard specs that should be added for top-level targets. This value is controlled by Java configuration.

stamp_manifest

AndroidManifestInfo android_data.stamp_manifest(ctx, *, manifest=None, custom_package=None, exports_manifest=False)

Stamps a manifest with package information.

Parameters

Parameter Description
ctx

AndroidDataContext

The Android data context object for this target.

manifest

File

The manifest to stamp. If not passed, a dummy manifest will be generated.

custom_package

string

The Android application package to stamp the manifest with. If not provided, the current Java package, derived from the location of this target's BUILD file, will be used. For example, given a BUILD file in 'java/com/foo/bar/BUILD', the package would be 'com.foo.bar'.

exports_manifest

bool

Defaults to False. If passed as True, this manifest will be exported to and eventually merged into targets that depend on it. Otherwise, it won't be inherited.