mod build_apks;
mod build_bundle;
mod extract_apks;
mod get_device_spec;
mod get_size_total;
mod install_apks;
pub use build_apks::*;
pub use build_bundle::*;
pub use extract_apks::*;
pub use get_device_spec::*;
pub use get_size_total::*;
pub use install_apks::*;
use crate::{bundletool, error::*};
use std::{
path::{Path, PathBuf},
process::Command,
};
const BUNDLETOOL_VERSION: &str = "1.8.2";
#[derive(Clone, Copy)]
pub struct Bundletool;
impl Bundletool {
pub fn build_apks(self, bundle: &Path, output: &Path) -> BuildApks {
BuildApks::new(bundle, output)
}
pub fn build_bundle(self, modules: &[PathBuf], output: &Path) -> BuildBundle {
BuildBundle::new(modules, output)
}
pub fn get_size_total(self, apks: &Path) -> GetSizeTotal {
GetSizeTotal::new(apks)
}
pub fn extract_apks(self, apks: &Path, output_dir: &Path, device_spec: &Path) -> ExtractApks {
ExtractApks::new(apks, output_dir, device_spec)
}
pub fn install_apks(self, apks: PathBuf) -> InstallApks {
InstallApks::new(&apks)
}
pub fn get_device_spec(self, output: &Path) -> GetDeviceSpec {
GetDeviceSpec::new(output)
}
}
pub fn bundletool() -> Result<Command> {
let mut bundletool_init = Command::new("java");
bundletool_init.arg("-jar");
if let Ok(bundletool_path) = std::env::var("BUNDLETOOL_PATH") {
bundletool_init.arg(bundletool_path);
} else {
let env_version =
std::env::var("BUNDLETOOL_VERSION").unwrap_or_else(|_| BUNDLETOOL_VERSION.to_string());
let bundletool_file = format!("bundletool-all-{}.jar", env_version);
let bundletool_file_path = dirs::home_dir()
.ok_or(Error::UnableToAccessHomeDirectory)?
.join(bundletool_file);
if bundletool_file_path.exists() {
bundletool_init.arg(bundletool_file_path);
} else {
return Err(Error::BundletoolNotFound);
}
}
Ok(bundletool_init)
}