creator_tools/commands/android/
sign_apk.rs

1use crate::error::*;
2use crate::tools::*;
3use std::path::{Path, PathBuf};
4
5/// Key for signing APK.
6#[derive(Debug)]
7pub struct Key {
8    pub path: PathBuf,
9    pub password: String,
10}
11
12/// Signs APK with given key.
13/// Uses `apksigner` build tool.
14pub fn sign_apk(sdk: &AndroidSdk, apk_path: &Path, key: Key) -> Result<()> {
15    let mut apksigner = sdk.build_tool(bat!("apksigner"), None)?;
16    apksigner
17        .arg("sign")
18        .arg("--ks")
19        .arg(&key.path)
20        .arg("--ks-pass")
21        .arg(format!("pass:{}", &key.password))
22        .arg(apk_path);
23    apksigner.output_err(true)?;
24    Ok(())
25}