1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::{error::*, types::*};
use std::path::{Path, PathBuf};

/// Aligns APK on 4-byte memory boundary.
/// Uses `zipalign` build tools
pub fn align_apk(
    sdk: &AndroidSdk,
    unaligned_apk_path: &Path,
    package_name: &str,
    build_dir: &Path,
) -> Result<PathBuf> {
    let unsigned_apk_path = build_dir.join(format!("{}.apk", package_name));
    let mut zipalign = sdk.build_tool(bin!("zipalign"), None)?;
    zipalign
        .arg("-f")
        .arg("-v")
        .arg("4")
        .arg(unaligned_apk_path)
        .arg(&unsigned_apk_path);
    zipalign.output_err(true)?;
    Ok(unsigned_apk_path)
}