android_tools/bundletool/extract_apks.rs
1use super::bundletool;
2use crate::error::*;
3use std::path::{Path, PathBuf};
4
5/// ## Extract device-specific APKs from an existing APK set
6///
7/// If you have an existing APK set and you want to extract from it a subset of APKs
8/// that target a specific device configuration, you can use the `extract-apk` command
9/// and specify a device specification JSON, as follows:
10///
11/// ```sh
12/// `bundletool extract-apks
13/// --apks=/MyApp/my_existing_APK_set.apks
14/// --output-dir=/MyApp/my_pixel2_APK_set.apks
15/// --device-spec=/MyApp/bundletool/pixel2.json`
16/// ```
17pub struct ExtractApks {
18 apks: PathBuf,
19 device_spec: PathBuf,
20 output_dir: PathBuf,
21}
22
23impl ExtractApks {
24 /// Specifies the path to the device spec file (from get-device-spec or constructed
25 /// manually) to use for matching
26 pub fn new(apks: &Path, device_spec: &Path, output_dir: &Path) -> Self {
27 Self {
28 apks: apks.to_owned(),
29 device_spec: device_spec.to_owned(),
30 output_dir: output_dir.to_owned(),
31 }
32 }
33
34 /// Runs `bundletool` commands to extract apks on your device or emulator
35 pub fn run(&self) -> Result<()> {
36 let mut extract_apks = bundletool()?;
37 extract_apks.arg("--apks");
38 extract_apks.arg(&self.apks);
39 extract_apks.arg("--device-spec");
40 extract_apks.arg(&self.device_spec);
41 extract_apks.arg("--output-dir");
42 extract_apks.arg(&self.output_dir);
43 extract_apks.output_err(true)?;
44 Ok(())
45 }
46}