android_tools/bundletool/install_apks.rs
1use super::bundletool;
2use crate::error::*;
3use std::path::{Path, PathBuf};
4
5/// ## Deploy APKs to a connected device
6///
7/// After you generate a set of APKs, bundletool can deploy the right combination of APKs
8/// from that set to a connected device.
9///
10/// For example, if you have a connected device running Android 5.0 (API level 21)
11/// or higher, bundletool pushes the base APK, feature module APKs, and configuration
12/// APKs required to run your app on that device. Alternatively, if your connected device
13/// is running Android 4.4 (API level 20) or lower, `bundletool` looks for a compatible
14/// multi-APK and deploys it to your device.
15///
16/// To deploy your app from an APK set, use theinstall-apks command and specify the path
17/// of the APK set using the `--apks=/path/to/apks` flag, as shown below. (If you have
18/// multiple devices connected, specify a target device by adding the
19/// `--device-id=serial-id` flag.)
20#[derive(Debug, Default)]
21pub struct InstallApks {
22 apks: PathBuf,
23 local_testing: bool,
24 device_id: Option<String>,
25}
26
27impl InstallApks {
28 /// Specifies path to set of apks to install it on your device or emulator
29 pub fn new(apks: &Path) -> Self {
30 Self {
31 apks: apks.to_owned(),
32 ..Default::default()
33 }
34 }
35
36 /// If you're using the `--local-testing` flag with the `build-apks` command, for
37 /// local testing to work correctly, you need to use `install-apks` to install
38 /// your APKs
39 pub fn local_testing(&mut self, local_testing: bool) -> &mut Self {
40 self.local_testing = local_testing;
41 self
42 }
43
44 /// If you have multiple devices connected, specify a target device by adding the
45 /// `--device-id=serial-id` flag
46 pub fn device_id(&mut self, device_id: String) -> &mut Self {
47 self.device_id = Some(device_id);
48 self
49 }
50
51 /// Runs `bundletool` commands to install apks on your device or emulator
52 pub fn run(&self) -> Result<()> {
53 let mut install_apks = bundletool()?;
54 install_apks.arg("install-apks");
55 install_apks.arg("--apks");
56 install_apks.arg(&self.apks);
57 if self.local_testing {
58 install_apks.arg("--local-testing");
59 }
60 if let Some(device_id) = &self.device_id {
61 install_apks.arg("--device-id").arg(device_id);
62 }
63 install_apks.output_err(true)?;
64 Ok(())
65 }
66}