android_tools_rs/aapt2/
mod.rs

1//! Android Asset Packaging Tool 2.0 (AAPT2).
2//! https://developer.android.com/studio/command-line/aapt2
3//! https://android.googlesource.com/platform/frameworks/base/+/master/tools/aapt2
4//!
5//! The main idea behind AAPT2, apart from new features, is that it divides
6//! the 'package' step into two: 'compile' and 'link'. It improves performance,
7//! since if only one file changes, you only need to recompile that one file and
8//! link all the intermediate files with the 'link' command.
9
10mod compile;
11mod convert;
12mod daemon;
13mod diff;
14mod dump;
15mod link;
16mod optimize;
17mod version;
18
19pub use compile::*;
20pub use convert::*;
21pub use daemon::*;
22pub use diff::*;
23pub use dump::*;
24pub use link::*;
25pub use optimize::*;
26pub use version::*;
27
28use self::{daemon::Aapt2Daemon, diff::Aapt2Diff, version::Aapt2Version};
29use std::path::{Path, PathBuf};
30
31#[derive(Clone, Copy)]
32pub struct Aapt2;
33
34impl Aapt2 {
35    /// Compiles resources incrementally from given resource path
36    pub fn compile_incremental(self, res_path: &Path, compiled_res: &Path) -> Aapt2Compile {
37        Aapt2Compile::new(res_path, compiled_res)
38    }
39
40    /// Compiles resources from given resource dir
41    pub fn compile_dir(self, res_dir: &Path, compiled_res: &Path) -> Aapt2Compile {
42        Aapt2Compile::new_from_res_dir(res_dir, compiled_res)
43    }
44
45    /// Compiles resources from given resource zip
46    pub fn compile_zip(self, res_zip: &Path, compiled_res: &Path) -> Aapt2Compile {
47        Aapt2Compile::new_from_res_zip(res_zip, compiled_res)
48    }
49
50    /// Links given list of resources into an apk
51    pub fn link_inputs(self, inputs: &[PathBuf], output_apk: &Path, manifest: &Path) -> Aapt2Link {
52        Aapt2Link::new(inputs, output_apk, manifest)
53    }
54
55    /// Links resources from given /compiled_res folder into an apk
56    pub fn link_compiled_res(
57        self,
58        compiled_res: Option<PathBuf>,
59        output_apk: &Path,
60        manifest: &Path,
61    ) -> Aapt2Link {
62        Aapt2Link::new_from_compiled_res(compiled_res, output_apk, manifest)
63    }
64
65    /// Used for printing information about the APK you generated using the link command
66    pub fn dump(self, subcommand: SubCommand, filename_apk: &Path) -> Aapt2Dump {
67        Aapt2Dump::new(subcommand, filename_apk)
68    }
69
70    /// Prints the differences in resources of two apks.
71    /// https://gerrit.pixelexperience.org/plugins/gitiles/frameworks_base/+/refs/tags/android-10.0.0_r2/tools/aapt2/cmd/Diff.cpp
72    pub fn diff(self, file: &[PathBuf]) -> Aapt2Diff {
73        Aapt2Diff::new(file)
74    }
75
76    /// Preforms resource optimizations on an apk
77    pub fn optimize(self, output_apk: &Path, output_dir: &Path) -> Aapt2Optimize {
78        Aapt2Optimize::new(output_apk, output_dir)
79    }
80
81    /// Converts an apk between binary and proto formats
82    pub fn convert(self, o: &Path) -> Aapt2Convert {
83        Aapt2Convert::new(o)
84    }
85
86    /// Prints the version of aapt2
87    pub fn version(self, version: String) -> Aapt2Version {
88        Aapt2Version::new(version)
89    }
90
91    /// Runs aapt in daemon mode. Each subsequent line is a single parameter to the
92    /// command. The end of an invocation is signaled by providing an empty line
93    pub fn daemon(self, trace_folder: &Path) -> Aapt2Daemon {
94        Aapt2Daemon::new(trace_folder)
95    }
96}