pub struct Aapt2Link { /* private fields */ }
Expand description
§Link
In the link phase, AAPT2 merges all the intermediate files generated from the
compilation phase such as resource tables, binary XML files, and processed
PNG files and packages them into a single APK. Additionally, other auxiliary
files like R.java
and ProGuard rules files can be generated during this phase.
However, the generated APK does not contain DEX bytecode and is unsigned.
That is, you canât deploy this APK to a device. If youâre not using the Android
Gradle Plugin to build your app from the command line
, you can use other command
line tools, such as d8
to compile Java bytecode into DEX bytecode and
apksigner
to sign your APK.
§Link syntax
The general syntax for using link is as follows:
aapt2 link path-to-input-files [options] -o
outputdirectory/outputfilename.apk --manifest AndroidManifest.xml
In the following example, AAPT2 merges the two intermediate files -
drawable_Image.flat
and values_values.arsc.flat
, and the AndroidManifest.xml
file. AAPT2 links the result against android.jar
file which holds the resources
defined in the android package:
aapt2 link -o output.apk
-I android_sdk/platforms/android_version/android.jar
compiled/res/values_values.arsc.flat
compiled/res/drawable_Image.flat --manifest /path/to/AndroidManifest.xml -v
Implementations§
Source§impl Aapt2Link
impl Aapt2Link
Sourcepub fn new(inputs: &[PathBuf], output_apk: &Path, manifest: &Path) -> Self
pub fn new(inputs: &[PathBuf], output_apk: &Path, manifest: &Path) -> Self
Specifies the output path for the linked resource APK.
This is a required flag because you must specify the path for the output APK that can hold the linked resources.
Specifies the path to the Android manifest file to build.
This is a required flag because the manifest file encloses essential information about your app like package name and application ID.
Sourcepub fn new_from_compiled_res(
compiled_res: Option<PathBuf>,
output_apk: &Path,
manifest: &Path,
) -> Self
pub fn new_from_compiled_res( compiled_res: Option<PathBuf>, output_apk: &Path, manifest: &Path, ) -> Self
Specifies the output path for the linked resource APK.
This is a required flag because you must specify the path for the output APK that can hold the linked resources.
Specifies the path to the Android manifest file to build.
This is a required flag because the manifest file encloses essential information about your app like package name and application ID.
Sourcepub fn proguard_main_dex(&mut self, proguard_main_dex: PathBuf) -> &mut Self
pub fn proguard_main_dex(&mut self, proguard_main_dex: PathBuf) -> &mut Self
Generates output file for ProGuard rules for the main dex.
Sourcepub fn proguard_minimal_keep_rules(
&mut self,
proguard_minimal_keep_rules: bool,
) -> &mut Self
pub fn proguard_minimal_keep_rules( &mut self, proguard_minimal_keep_rules: bool, ) -> &mut Self
Generate a minimal set of Proguard keep rules.
Sourcepub fn no_resource_removal(&mut self, no_resource_removal: bool) -> &mut Self
pub fn no_resource_removal(&mut self, no_resource_removal: bool) -> &mut Self
Disables automatic removal of resources without
Sourcepub fn package_identifier(&mut self, package_identifier: bool) -> &mut Self
pub fn package_identifier(&mut self, package_identifier: bool) -> &mut Self
Legacy flag that specifies to use the package identifier 0x01.
Sourcepub fn product(&mut self, product: PathBuf) -> &mut Self
pub fn product(&mut self, product: PathBuf) -> &mut Self
Comma separated list of product names to keep
Sourcepub fn no_xml_namespaces(&mut self, no_xml_namespaces: bool) -> &mut Self
pub fn no_xml_namespaces(&mut self, no_xml_namespaces: bool) -> &mut Self
Removes XML namespace prefix and URI information
Sourcepub fn version_code_major(&mut self, version_code_major: u32) -> &mut Self
pub fn version_code_major(&mut self, version_code_major: u32) -> &mut Self
Version code major (integer) to inject into the AndroidManifest.xml if none is present.
Sourcepub fn version_name(&mut self, version_name: String) -> &mut Self
pub fn version_name(&mut self, version_name: String) -> &mut Self
Version name to inject into the AndroidManifest.xml if none is present.
Sourcepub fn replace_version(&mut self, replace_version: bool) -> &mut Self
pub fn replace_version(&mut self, replace_version: bool) -> &mut Self
If âversion-code and/or âversion-name are specified, these values will replace any value already in the manifest. By default, nothing is changed if the manifest already defines these attributes.
Sourcepub fn compile_sdk_version_code(
&mut self,
compile_sdk_version_code: u32,
) -> &mut Self
pub fn compile_sdk_version_code( &mut self, compile_sdk_version_code: u32, ) -> &mut Self
Version code (integer) to inject into the AndroidManifest.xml if none is present.
Generates a shared Android runtime library.
Sourcepub fn static_lib(&mut self, static_lib: bool) -> &mut Self
pub fn static_lib(&mut self, static_lib: bool) -> &mut Self
Generate a static Android library.
Sourcepub fn no_static_lib_packages(
&mut self,
no_static_lib_packages: bool,
) -> &mut Self
pub fn no_static_lib_packages( &mut self, no_static_lib_packages: bool, ) -> &mut Self
Merge all library resources under the appâs package.
Sourcepub fn no_proguard_location_reference(
&mut self,
no_proguard_location_reference: bool,
) -> &mut Self
pub fn no_proguard_location_reference( &mut self, no_proguard_location_reference: bool, ) -> &mut Self
Keep proguard rules files from having a reference to the source file
Sourcepub fn private_symbols(&mut self, private_symbols: String) -> &mut Self
pub fn private_symbols(&mut self, private_symbols: String) -> &mut Self
Package name to use when generating R.java for private symbols. If not specified, public and private symbols will use the applicationâs package name.
Sourcepub fn override_styles_instead_of_overlaying(
&mut self,
override_styles_instead_of_overlaying: bool,
) -> &mut Self
pub fn override_styles_instead_of_overlaying( &mut self, override_styles_instead_of_overlaying: bool, ) -> &mut Self
Causes styles defined in -R resources to replace previous definitions instead of merging into them
Sourcepub fn rename_resources_package(
&mut self,
rename_resources_package: String,
) -> &mut Self
pub fn rename_resources_package( &mut self, rename_resources_package: String, ) -> &mut Self
Renames the package in resources table
Sourcepub fn android_jar(&mut self, android_jar: PathBuf) -> &mut Self
pub fn android_jar(&mut self, android_jar: PathBuf) -> &mut Self
Provides the path to the platformâs android.jar or other APKs like framework-res.apk which might be useful while building features. This flag is required if you are using attributes with android namespace (for example, android:id) in your resource files.
Sourcepub fn assets(&mut self, assets: PathBuf) -> &mut Self
pub fn assets(&mut self, assets: PathBuf) -> &mut Self
Specifies an assets directory to be included in the APK.
You can use this directory to store original unprocessed files. To learn more,
read Accessing original
files.
Sourcepub fn individual_flat(&mut self, individual_flat: PathBuf) -> &mut Self
pub fn individual_flat(&mut self, individual_flat: PathBuf) -> &mut Self
Pass individual .flat file to link, using overlay
semantics without using the
<add-resource>
tag.
When you a provide a resource file that overlays (extends or modifies) an existing file, the last conflicting resource given is used.
Sourcepub fn package_id(&mut self, package_id: String) -> &mut Self
pub fn package_id(&mut self, package_id: String) -> &mut Self
Specifies the package ID to use for your app.
The package ID that you specify must be greater than or equal to 0x7f unless used
in combination with --allow-reserved-package-id
.
Sourcepub fn allow_reserved_package_id(
&mut self,
allow_reserved_package_id: bool,
) -> &mut Self
pub fn allow_reserved_package_id( &mut self, allow_reserved_package_id: bool, ) -> &mut Self
Allows the use of a reserved package ID.
Reserved package IDs are IDs that are normally assigned to shared libraries and are in the range from 0x02 to 0x7e inclusive. By using âallow-reserved-package-id, you can assign IDs that fall in the range of reserved package IDs.
This should only be used for packages with a min-sdk version of 26 or lower.
Sourcepub fn java(&mut self, java: PathBuf) -> &mut Self
pub fn java(&mut self, java: PathBuf) -> &mut Self
Specifies the directory in which to generate R.java.
Sourcepub fn proguard_options(&mut self, proguard_options: PathBuf) -> &mut Self
pub fn proguard_options(&mut self, proguard_options: PathBuf) -> &mut Self
Generates output file for ProGuard rules.
Sourcepub fn proguard_conditional_keep_rules(
&mut self,
proguard_conditional_keep_rules: bool,
) -> &mut Self
pub fn proguard_conditional_keep_rules( &mut self, proguard_conditional_keep_rules: bool, ) -> &mut Self
Output file for generated Proguard rules for the main dex.
Sourcepub fn no_auto_version(&mut self, no_auto_version: bool) -> &mut Self
pub fn no_auto_version(&mut self, no_auto_version: bool) -> &mut Self
Disables automatic style and layout SDK versioning.
Sourcepub fn no_version_vectors(&mut self, no_version_vectors: bool) -> &mut Self
pub fn no_version_vectors(&mut self, no_version_vectors: bool) -> &mut Self
Disables automatic versioning of vector drawables. Use this only when building your APK with the Vector Drawable Library.
Sourcepub fn no_version_transitions(
&mut self,
no_version_transitions: bool,
) -> &mut Self
pub fn no_version_transitions( &mut self, no_version_transitions: bool, ) -> &mut Self
Disables automatic versioning of transition resources. Use this only when building your APK with Transition Support library.
Sourcepub fn no_resource_deduping(&mut self, no_resource_deduping: bool) -> &mut Self
pub fn no_resource_deduping(&mut self, no_resource_deduping: bool) -> &mut Self
Disables automatic de-duplication of resources with identical values across compatible configurations.
Sourcepub fn enable_sparse_encoding(
&mut self,
enable_sparse_encoding: bool,
) -> &mut Self
pub fn enable_sparse_encoding( &mut self, enable_sparse_encoding: bool, ) -> &mut Self
Enables encoding of sparse entries using a binary search tree. This is useful for optimization of APK size, but at the cost of resource retrieval performance.
Sourcepub fn suggested_strings(&mut self, suggested_strings: bool) -> &mut Self
pub fn suggested_strings(&mut self, suggested_strings: bool) -> &mut Self
Requires localization of strings marked âsuggestedâ.
Sourcepub fn config(&mut self, config: String) -> &mut Self
pub fn config(&mut self, config: String) -> &mut Self
Provides a list of configurations separated by commas.
For example, if you have dependencies on the support library (which contains translations for multiple languages), you can filter resources just for the given language configuration, like English or Spanish.
You must define the language configuration by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code preceded by lowercase ârâ (for example, en-rUS).
Sourcepub fn preferred_density(&mut self, preferred_density: i32) -> &mut Self
pub fn preferred_density(&mut self, preferred_density: i32) -> &mut Self
Allows AAPT2 to select the closest matching density and strip out all others.
There are several pixel density qualifiers available to use in your app, such as ldpi, hdpi, and xhdpi. When you specify a preferred density, AAPT2 selects and stores the closest matching density in the resource table and removes all others.
Sourcepub fn output_to_dir(&mut self, output_to_dir: bool) -> &mut Self
pub fn output_to_dir(&mut self, output_to_dir: bool) -> &mut Self
Outputs the APK contents to a directory specified by -o.
If you get any errors using this flag, you can resolve them by upgrading to
Android SDK Build Tools 28.0.0 or higher
.
Sourcepub fn min_sdk_version(&mut self, min_sdk_version: u32) -> &mut Self
pub fn min_sdk_version(&mut self, min_sdk_version: u32) -> &mut Self
Sets the default minimum SDK version to use for AndroidManifest.xml
.
Sourcepub fn target_sdk_version(&mut self, target_sdk_version: u32) -> &mut Self
pub fn target_sdk_version(&mut self, target_sdk_version: u32) -> &mut Self
Sets the default target SDK version to use for AndroidManifest.xml
.
Sourcepub fn version_code(&mut self, version_code: u32) -> &mut Self
pub fn version_code(&mut self, version_code: u32) -> &mut Self
Specifies the version code (integer) to inject into the AndroidManifest.xml if none is present.
Sourcepub fn compile_sdk_version_name(
&mut self,
compile_sdk_version_name: String,
) -> &mut Self
pub fn compile_sdk_version_name( &mut self, compile_sdk_version_name: String, ) -> &mut Self
Specifies the version name to inject into the AndroidManifest.xml if none is present.
Sourcepub fn proto_format(&mut self, proto_format: bool) -> &mut Self
pub fn proto_format(&mut self, proto_format: bool) -> &mut Self
Generates compiled resources in Protobuf format.
Suitable as input to the bundle tool
for generating an Android App Bundle.
Sourcepub fn non_final_ids(&mut self, non_final_ids: bool) -> &mut Self
pub fn non_final_ids(&mut self, non_final_ids: bool) -> &mut Self
Generates R.java
with non-final resource IDs (references to the IDs from appâs
code will not get inlined during kotlinc/javac compilation).
Sourcepub fn emit_ids(&mut self, emit_ids: PathBuf) -> &mut Self
pub fn emit_ids(&mut self, emit_ids: PathBuf) -> &mut Self
Emits a file at the given path with a list of names of resource types and their ID mappings. It is suitable to use with âstable-ids.
Sourcepub fn stable_ids(&mut self, stable_ids: PathBuf) -> &mut Self
pub fn stable_ids(&mut self, stable_ids: PathBuf) -> &mut Self
Consumes the file generated with âemit-ids containing the list of names of resource types and their assigned IDs.
This option allows assigned IDs to remain stable even when you delete or add new resources while linking
Sourcepub fn custom_package(&mut self, custom_package: PathBuf) -> &mut Self
pub fn custom_package(&mut self, custom_package: PathBuf) -> &mut Self
Specifies custom Java package under which to generate R.java.
Sourcepub fn extra_packages(&mut self, extra_packages: PathBuf) -> &mut Self
pub fn extra_packages(&mut self, extra_packages: PathBuf) -> &mut Self
Generates the same R.java file but with different package names.
Sourcepub fn add_javadoc_annotation(
&mut self,
add_javadoc_annotation: String,
) -> &mut Self
pub fn add_javadoc_annotation( &mut self, add_javadoc_annotation: String, ) -> &mut Self
Adds a JavaDoc annotation to all generated Java classes.
Sourcepub fn output_text_symbols(&mut self, output_text_symbols: PathBuf) -> &mut Self
pub fn output_text_symbols(&mut self, output_text_symbols: PathBuf) -> &mut Self
Generates a text file containing the resource symbols of the R class in the specified file.
You must specify the path to the output file.
Sourcepub fn auto_add_overlay(&mut self, auto_add_overlay: bool) -> &mut Self
pub fn auto_add_overlay(&mut self, auto_add_overlay: bool) -> &mut Self
Allows the addition of new resources in overlays without using the
Sourcepub fn rename_manifest_package(
&mut self,
rename_manifest_package: String,
) -> &mut Self
pub fn rename_manifest_package( &mut self, rename_manifest_package: String, ) -> &mut Self
Renames the package in AndroidManifest.xml.
Sourcepub fn rename_instrumentation_target_package(
&mut self,
rename_instrumentation_target_package: String,
) -> &mut Self
pub fn rename_instrumentation_target_package( &mut self, rename_instrumentation_target_package: String, ) -> &mut Self
Changes the name of the target package for instrumentation
.
It should be used in conjunction with ârename-manifest-package.
Sourcepub fn no_compress(&mut self, no_compress: bool) -> &mut Self
pub fn no_compress(&mut self, no_compress: bool) -> &mut Self
Do not compress any resources.
Sourcepub fn keep_raw_values(&mut self, keep_raw_values: bool) -> &mut Self
pub fn keep_raw_values(&mut self, keep_raw_values: bool) -> &mut Self
Preserve raw attribute values in xml files.
Sourcepub fn extension(&mut self, extension: String) -> &mut Self
pub fn extension(&mut self, extension: String) -> &mut Self
Specifies the extensions of files that you do not want to compress.
Sourcepub fn no_compress_regex(&mut self, no_compress_regex: String) -> &mut Self
pub fn no_compress_regex(&mut self, no_compress_regex: String) -> &mut Self
Do not compress extensions matching the regular expression. Remember to use the â$â symbol for end of line. Uses a case-sensitive ECMAScriptregular expression grammar.
Sourcepub fn warn_manifest_validation(
&mut self,
warn_manifest_validation: bool,
) -> &mut Self
pub fn warn_manifest_validation( &mut self, warn_manifest_validation: bool, ) -> &mut Self
Treat manifest validation errors as warnings.
Sourcepub fn split(&mut self, split: PathBuf) -> &mut Self
pub fn split(&mut self, split: PathBuf) -> &mut Self
Splits resources based on a set of configurations to generate a different version of the APK.
You must specify the path to the output APK along with the set of configurations.
Sourcepub fn strict_visibility(&mut self, strict_visibility: bool) -> &mut Self
pub fn strict_visibility(&mut self, strict_visibility: bool) -> &mut Self
Do not allow overlays with different visibility levels.
Sourcepub fn trace_folder(&mut self, trace_folder: String) -> &mut Self
pub fn trace_folder(&mut self, trace_folder: String) -> &mut Self
Generate systrace json trace fragment to specified folder.
Sourcepub fn exclude_sources(&mut self, exclude_sources: bool) -> &mut Self
pub fn exclude_sources(&mut self, exclude_sources: bool) -> &mut Self
Do not serialize source file information when generating resources in Protobuf format.
Sourcepub fn merge_only(&mut self, merge_only: bool) -> &mut Self
pub fn merge_only(&mut self, merge_only: bool) -> &mut Self
Only merge the resources, without verifying resource references. This flag should only be used together with the âstatic-lib flag.
Sourcepub fn verbose(&mut self, verbose: bool) -> &mut Self
pub fn verbose(&mut self, verbose: bool) -> &mut Self
Enables increased verbosity of the output.