Aapt2Compile

Struct Aapt2Compile 

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

§Compile

AAPT2 supports compilation of all Android resource types, such as drawables and XML files. When you invoke AAPT2 for compilation, you should pass a single resource file as an input per invocation. AAPT2 then parses the file and generates an intermediate binary file with a .flat extension.

Although you can pass resource directories containing more than one resource files to AAPT2 using the --dir flag, you do not gain the benefits of incremental resource compilation when doing so. That is, when passing whole directories, AAPT2 recompiles all files in the directory even when only one resource has changed.

The output file types can differ based on the input you provide for compilation. The files AAPT2 outputs are not executables and you must later include these binary files as input in the link phase to generate an APK. However, the generated APK file is not an executable that you can deploy on an Android device right away, as it does not contain DEX files (compiled bytecode) and is not signed.

§Compile syntax

The general syntax for using compile is as follows:

`aapt2 compile path-to-input-files [options] -o output-directory/`

§Note

For resource files, the path to input files must match the following structure:

`path/resource-type[-config]/file`

In the following example, AAPT2 compiles resource files named values.xml and myImage.png individually:

`aapt2 compile project_root/module_root/src/main/res/values-en/strings.xml -o compiled/`
`aapt2 compile project_root/module_root/src/main/res/drawable/myImage.png -o compiled/`

As shown in the table above, the name of the output file depends on the input file name and the name of its parent directory (the resource type and configuration). For the example above with strings.xml as input, aapt2 automatically names the output file as values-en_strings.arsc.flat. On the other hand, the file name for the compiled drawable file stored in the drawable directory will be drawable_img.png.flat.

§Compile options

Implementations§

Source§

impl Aapt2Compile

Source

pub fn new(res_path: &Path, compiled_res: &Path) -> Aapt2Compile

Initialize aapt2 compile then specifies input resource(s) to compile and specifies the output path for the compiled resource(s)

Source

pub fn new_from_res_dir(res_dir: &Path, compiled_res: &Path) -> Aapt2Compile

Specifies the directory to scan for resources and specifies the output path for the compiled resource(s).

Although you can use this flag to compile multiple resource files with one command, it disables the benefits of incremental compilation and thus, should not be used for large projects

Source

pub fn new_from_res_zip(res_zip: &Path, compiled_res: &Path) -> Aapt2Compile

Specifies zip file containing the res directory to scan for resources and specifies the output path for the compiled resource(s)

Source

pub fn output_text_symbols( &mut self, output_text_symbols: String, ) -> &mut Aapt2Compile

Generates a text file containing the resource symbols in the specified file

Source

pub fn pseudo_localize(&mut self, pseudo_localize: bool) -> &mut Aapt2Compile

Generates pseudo-localized versions of default strings, such as en-XA and en-XB

Source

pub fn no_crunch(&mut self, no_crunch: bool) -> &mut Aapt2Compile

Disables PNG processing.

Use this option if you have already processed the PNG files, or if you are creating debug builds that do not require file size reduction. Enabling this option results in a faster execution, but increases the output file size

Source

pub fn legacy(&mut self, legacy: bool) -> &mut Aapt2Compile

Treats errors that are permissible when using earlier versions of AAPT as warnings.

This flag should be used for unexpected compile time errors. To resolve known behavior changes that you might get while using AAPT2, read Behavior changes in AAPT2.

Source

pub fn preserve_visibility_of_styleables( &mut self, preserve_visibility_of_styleables: bool, ) -> &mut Aapt2Compile

If specified, apply the same visibility rules for styleables as are used for all other resources. Otherwise, all stylesables will be made public

Source

pub fn visibility(&mut self, visibility: Visibility) -> &mut Aapt2Compile

Sets the visibility of the compiled resources to the specified level. Accepted levels: public, private, default

Source

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

Enable verbose logging

Source

pub fn trace_folder(&mut self, trace_folder: &Path) -> &mut Aapt2Compile

Generate systrace json trace fragment to specified folder

Source

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

Displays this help menu

Source

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

Executes aapt2 compile with arguments

Trait Implementations§

Source§

impl Clone for Aapt2Compile

Source§

fn clone(&self) -> Aapt2Compile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Aapt2Compile

Source§

fn default() -> Aapt2Compile

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,