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
impl Aapt2Compile
Sourcepub fn new(res_path: &Path, compiled_res: &Path) -> Self
pub fn new(res_path: &Path, compiled_res: &Path) -> Self
Initialize struct Aapt2Compile then specifies input resource(s) to compile and specifies the output path for the compiled resource(s)
Sourcepub fn new_from_res_dir(res_dir: &Path, compiled_res: &Path) -> Self
pub fn new_from_res_dir(res_dir: &Path, compiled_res: &Path) -> Self
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
Sourcepub fn new_from_res_zip(res_zip: &Path, compiled_res: &Path) -> Self
pub fn new_from_res_zip(res_zip: &Path, compiled_res: &Path) -> Self
Specifies zip file containing the res directory to scan for resources and specifies the output path for the compiled resource(s)
Sourcepub fn output_text_symbols(&mut self, output_text_symbols: String) -> &mut Self
pub fn output_text_symbols(&mut self, output_text_symbols: String) -> &mut Self
Generates a text file containing the resource symbols in the specified file
Sourcepub fn pseudo_localize(&mut self, pseudo_localize: bool) -> &mut Self
pub fn pseudo_localize(&mut self, pseudo_localize: bool) -> &mut Self
Generates pseudo-localized versions of default strings, such as en-XA and en-XB
Sourcepub fn no_crunch(&mut self, no_crunch: bool) -> &mut Self
pub fn no_crunch(&mut self, no_crunch: bool) -> &mut Self
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
Sourcepub fn legacy(&mut self, legacy: bool) -> &mut Self
pub fn legacy(&mut self, legacy: bool) -> &mut Self
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.
Sourcepub fn preserve_visibility_of_styleables(
&mut self,
preserve_visibility_of_styleables: bool,
) -> &mut Self
pub fn preserve_visibility_of_styleables( &mut self, preserve_visibility_of_styleables: bool, ) -> &mut Self
If specified, apply the same visibility rules for styleables as are used for all other resources. Otherwise, all stylesables will be made public
Sourcepub fn visibility(&mut self, visibility: Visibility) -> &mut Self
pub fn visibility(&mut self, visibility: Visibility) -> &mut Self
Sets the visibility of the compiled resources to the specified level. Accepted levels: public, private, default
Sourcepub fn trace_folder(&mut self, trace_folder: &Path) -> &mut Self
pub fn trace_folder(&mut self, trace_folder: &Path) -> &mut Self
Generate systrace json trace fragment to specified folder
Trait Implementationsยง
Sourceยงimpl Clone for Aapt2Compile
impl Clone for Aapt2Compile
Sourceยงfn clone(&self) -> Aapt2Compile
fn clone(&self) -> Aapt2Compile
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more