android_tools/aapt2/
mod.rs1mod 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 crate::{error::*, find_max_version, sdk_path_from_env};
30use std::{
31 path::{Path, PathBuf},
32 process::Command,
33};
34
35#[derive(Clone, Copy)]
41pub struct Aapt2;
42
43impl Aapt2 {
44 pub fn compile_incremental(self, res_path: &Path, compiled_res: &Path) -> Aapt2Compile {
46 Aapt2Compile::new(res_path, compiled_res)
47 }
48
49 pub fn compile_dir(self, res_dir: &Path, compiled_res: &Path) -> Aapt2Compile {
51 Aapt2Compile::new_from_res_dir(res_dir, compiled_res)
52 }
53
54 pub fn compile_zip(self, res_zip: &Path, compiled_res: &Path) -> Aapt2Compile {
56 Aapt2Compile::new_from_res_zip(res_zip, compiled_res)
57 }
58
59 pub fn link_inputs(self, inputs: &[PathBuf], output_apk: &Path, manifest: &Path) -> Aapt2Link {
61 Aapt2Link::new(inputs, output_apk, manifest)
62 }
63
64 pub fn link_compiled_res(
66 self,
67 compiled_res: Option<PathBuf>,
68 output_apk: &Path,
69 manifest: &Path,
70 ) -> Aapt2Link {
71 Aapt2Link::new_from_compiled_res(compiled_res, output_apk, manifest)
72 }
73
74 pub fn dump(self, subcommand: SubCommand, filename_apk: &Path) -> Aapt2Dump {
76 Aapt2Dump::new(subcommand, filename_apk)
77 }
78
79 pub fn diff(self, file: &[PathBuf]) -> Aapt2Diff {
81 Aapt2Diff::new(file)
82 }
83
84 pub fn optimize(self, output_apk: &Path, output_dir: &Path) -> Aapt2Optimize {
86 Aapt2Optimize::new(output_apk, output_dir)
87 }
88
89 pub fn convert(self, o: &Path) -> Aapt2Convert {
91 Aapt2Convert::new(o)
92 }
93
94 pub fn version(self, version: String) -> Aapt2Version {
96 Aapt2Version::new(version)
97 }
98
99 pub fn daemon(self, trace_folder: &Path) -> Aapt2Daemon {
102 Aapt2Daemon::new(trace_folder)
103 }
104}
105
106pub fn aapt2_tool() -> Result<Command> {
108 if let Ok(aapt2) = which::which(bin!("aapt2")) {
109 return Ok(Command::new(aapt2));
110 }
111 let sdk_path = sdk_path_from_env()?;
112 let build_tools = sdk_path.join("build-tools");
113 let target_sdk_version = find_max_version(&build_tools)?;
114 let aapt2_exe = build_tools.join(target_sdk_version).join(bin!("aapt2"));
115 Ok(Command::new(aapt2_exe))
116}