From 8da09673b42e43ac3b48b848e19f798945ba1b8a Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 10 Jun 2022 19:58:11 +0200 Subject: [PATCH] ndk-build,cargo-apk: Disable `aapt` compression for the `dev` profile (#283) Compressing multi-megabyte libraries in `aapt` is a singlethreaded process that takes many (tens of) seconds, for no apparent gain. It slows down the iterative development process significantly whereas there's no concern for `adb` transferring larger `apk`s over even USB 2.0 (which is still much faster than the bandwidth `aapt` provides for compression) nor typically any space constraints on development devices. The `-0` option disables compression for all files with a given extension, or all files when the argument is an empty string (`""`). --- cargo-apk/CHANGELOG.md | 3 ++- cargo-apk/src/apk.rs | 1 + ndk-build/CHANGELOG.md | 3 ++- ndk-build/src/apk.rs | 16 +++++++++++++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cargo-apk/CHANGELOG.md b/cargo-apk/CHANGELOG.md index 594a7005..2bad314c 100644 --- a/cargo-apk/CHANGELOG.md +++ b/cargo-apk/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased -- Move NDK r23 `-lgcc` workaround to `ndk-build::cargo::cargo_ndk`, to also apply to our `cargo apk --` invocations. ([#286](https://github.com/rust-windowing/android-ndk-rs/pull/286)) +- Move NDK r23 `-lgcc` workaround to `ndk_build::cargo::cargo_ndk()`, to also apply to our `cargo apk --` invocations. ([#286](https://github.com/rust-windowing/android-ndk-rs/pull/286)) +- Disable `aapt` compression for the [(default) `dev` profile](https://doc.rust-lang.org/cargo/reference/profiles.html). ([#283](https://github.com/rust-windowing/android-ndk-rs/pull/283)) # 0.9.1 (2022-05-12) diff --git a/cargo-apk/src/apk.rs b/cargo-apk/src/apk.rs index 892ba01d..d07472b7 100644 --- a/cargo-apk/src/apk.rs +++ b/cargo-apk/src/apk.rs @@ -167,6 +167,7 @@ impl<'a> ApkBuilder<'a> { assets, resources, manifest, + disable_aapt_compression: self.cmd.profile() == &Profile::Dev, }; let apk = config.create_apk()?; diff --git a/ndk-build/CHANGELOG.md b/ndk-build/CHANGELOG.md index 337ad6dd..0c26275a 100644 --- a/ndk-build/CHANGELOG.md +++ b/ndk-build/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased -- **Breaking:** Provide NDK r23 `-lgcc` workaround in `cargo_ndk` function, now requiring `target_dir` as argument. ([#286](https://github.com/rust-windowing/android-ndk-rs/pull/286)) +- **Breaking:** Provide NDK r23 `-lgcc` workaround in `cargo_ndk()` function, now requiring `target_dir` as argument. ([#286](https://github.com/rust-windowing/android-ndk-rs/pull/286)) +- **Breaking:** Add `disable_aapt_compression` field to `ApkConfig` to disable `aapt` compression. ([#283](https://github.com/rust-windowing/android-ndk-rs/pull/283)) # 0.5.0 (2022-05-07) diff --git a/ndk-build/src/apk.rs b/ndk-build/src/apk.rs index 08e22f04..1610a4e6 100644 --- a/ndk-build/src/apk.rs +++ b/ndk-build/src/apk.rs @@ -14,6 +14,7 @@ pub struct ApkConfig { pub assets: Option, pub resources: Option, pub manifest: AndroidManifest, + pub disable_aapt_compression: bool, } impl ApkConfig { @@ -51,6 +52,10 @@ impl ApkConfig { .arg("-I") .arg(self.ndk.android_jar(target_sdk_version)?); + if self.disable_aapt_compression { + aapt.arg("-0").arg(""); + } + if let Some(res) = &self.resources { aapt.arg("-S").arg(res); } @@ -90,9 +95,14 @@ impl<'a> UnalignedApk<'a> { let lib_path_unix = lib_path.to_str().unwrap().replace('\\', "/"); let mut aapt = self.0.build_tool(bin!("aapt"))?; - aapt.arg("add") - .arg(self.0.unaligned_apk()) - .arg(lib_path_unix); + aapt.arg("add"); + + if self.0.disable_aapt_compression { + aapt.arg("-0").arg(""); + } + + aapt.arg(self.0.unaligned_apk()).arg(lib_path_unix); + if !aapt.status()?.success() { return Err(NdkError::CmdFailed(aapt)); }