Struct Aapt2Link

Source
pub struct Aapt2Link { /* private fields */ }
Expand description

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.

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

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

Source

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

Source

pub fn proguard_main_dex(&mut self, proguard_main_dex: PathBuf) -> &mut Self

Generates output file for ProGuard rules for the main dex

Source

pub fn proguard_minimal_keep_rules( &mut self, proguard_minimal_keep_rules: bool, ) -> &mut Self

Generate a minimal set of Proguard keep rules

Source

pub fn no_resource_removal(&mut self, no_resource_removal: bool) -> &mut Self

Disables automatic removal of resources without

Source

pub fn package_identifier(&mut self, package_identifier: bool) -> &mut Self

Legacy flag that specifies to use the package identifier 0x01

Source

pub fn product(&mut self, product: PathBuf) -> &mut Self

Comma separated list of product names to keep

Source

pub fn no_xml_namespaces(&mut self, no_xml_namespaces: bool) -> &mut Self

Removes XML namespace prefix and URI information

Source

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

Source

pub fn version_name(&mut self, version_name: String) -> &mut Self

Version name to inject into the AndroidManifest.xml if none is present

Source

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

Source

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

Source

pub fn shared_lib(&mut self, shared_lib: bool) -> &mut Self

Generates a shared Android runtime library

Source

pub fn static_lib(&mut self, static_lib: bool) -> &mut Self

Generate a static Android library

Source

pub fn no_static_lib_packages( &mut self, no_static_lib_packages: bool, ) -> &mut Self

Merge all library resources under the app’s package

Source

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

Source

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

Source

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

Source

pub fn rename_resources_package( &mut self, rename_resources_package: String, ) -> &mut Self

Renames the package in resources table

Source

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

Source

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.

Source

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

Source

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

Source

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

Source

pub fn java(&mut self, java: PathBuf) -> &mut Self

Specifies the directory in which to generate R.java

Source

pub fn proguard_options(&mut self, proguard_options: PathBuf) -> &mut Self

Generates output file for ProGuard rules

Source

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

Source

pub fn no_auto_version(&mut self, no_auto_version: bool) -> &mut Self

Disables automatic style and layout SDK versioning

Source

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

Source

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

Source

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

Source

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

Source

pub fn suggested_strings(&mut self, suggested_strings: bool) -> &mut Self

Requires localization of strings marked ‘suggested’

Source

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).

Source

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.

Source

pub fn output_to_dir(&mut self, output_to_dir: &Path) -> &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.

Source

pub fn min_sdk_version(&mut self, min_sdk_version: u32) -> &mut Self

Sets the default minimum SDK version to use for AndroidManifest.xml

Source

pub fn target_sdk_version(&mut self, target_sdk_version: u32) -> &mut Self

Sets the default target SDK version to use for AndroidManifest.xml

Source

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

Source

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

Source

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.

Source

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)

Source

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

Source

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

Source

pub fn custom_package(&mut self, custom_package: PathBuf) -> &mut Self

Specifies custom Java package under which to generate R.java

Source

pub fn extra_packages(&mut self, extra_packages: PathBuf) -> &mut Self

Generates the same R.java file but with different package names

Source

pub fn add_javadoc_annotation( &mut self, add_javadoc_annotation: String, ) -> &mut Self

Adds a JavaDoc annotation to all generated Java classes

Source

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

Source

pub fn auto_add_overlay(&mut self, auto_add_overlay: bool) -> &mut Self

Allows the addition of new resources in overlays without using the tag

Source

pub fn rename_manifest_package( &mut self, rename_manifest_package: String, ) -> &mut Self

Renames the package in AndroidManifest.xml

Source

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.

Source

pub fn no_compress(&mut self, no_compress: bool) -> &mut Self

Do not compress any resources

Source

pub fn keep_raw_values(&mut self, keep_raw_values: bool) -> &mut Self

Preserve raw attribute values in xml files

Source

pub fn extension(&mut self, extension: String) -> &mut Self

Specifies the extensions of files that you do not want to compress

Source

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

Source

pub fn warn_manifest_validation( &mut self, warn_manifest_validation: bool, ) -> &mut Self

Treat manifest validation errors as warnings

Source

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

Source

pub fn strict_visibility(&mut self, strict_visibility: bool) -> &mut Self

Do not allow overlays with different visibility levels

Source

pub fn trace_folder(&mut self, trace_folder: String) -> &mut Self

Generate systrace json trace fragment to specified folder

Source

pub fn exclude_sources(&mut self, exclude_sources: bool) -> &mut Self

Do not serialize source file information when generating resources in Protobuf format

Source

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

Source

pub fn verbose(&mut self, verbose: bool) -> &mut Self

Enables increased verbosity of the output

Source

pub fn help(&mut self, help: bool) -> &mut Self

Displays this help menu

Source

pub fn run(&self) -> Result<PathBuf>

Executes aapt2 link with arguments

Trait Implementations§

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

fn default() -> Aapt2Link

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.