android_tools/bundletool/
get_device_spec.rs

1use super::bundletool;
2use crate::error::*;
3use std::path::{Path, PathBuf};
4
5/// ## Generate and use device specification JSON files
6///
7/// `Bundletool` is capable of generating an APK set that targets a device configuration
8/// specified by a JSON file. To first generate a JSON file for a connected device, run
9/// the following command:
10///
11/// ```sh
12/// `bundletool get-device-spec --output=/tmp/device-spec.json`
13/// ```
14///
15/// `bundletool` creates a JSON file for your device in the directory the tool is located.
16/// You can then pass it to `bundletool` to generate a set of APKs that target only the
17/// configuration described in that JSON file as follows:
18///
19/// ```sh
20/// `bundletool build-apks --device-spec=/MyApp/pixel2.json`
21/// `--bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks`
22/// ```
23#[derive(Debug)]
24pub struct GetDeviceSpec {
25    output: PathBuf,
26}
27impl GetDeviceSpec {
28    /// Connect your device or use emulator to get device specification in provided path using `bundletool`
29    pub fn new(output: &Path) -> Self {
30        Self {
31            output: output.to_owned(),
32        }
33    }
34
35    /// Runs `bundletool` commands to get device specification
36    pub fn run(&self) -> Result<()> {
37        let mut get_device_spec = bundletool()?;
38        get_device_spec.arg("get-device-spec");
39        get_device_spec.arg("--output").arg(&self.output);
40        get_device_spec.output_err(true)?;
41        Ok(())
42    }
43}