Skip to content

Commit

Permalink
ndk-build,cargo-apk: Disable aapt compression for the dev profile (
Browse files Browse the repository at this point in the history
…rust-mobile#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 (`""`).
  • Loading branch information
MarijnS95 authored Jun 10, 2022
1 parent 9ff0d10 commit 8da0967
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cargo-apk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
1 change: 1 addition & 0 deletions cargo-apk/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl<'a> ApkBuilder<'a> {
assets,
resources,
manifest,
disable_aapt_compression: self.cmd.profile() == &Profile::Dev,
};
let apk = config.create_apk()?;

Expand Down
3 changes: 2 additions & 1 deletion ndk-build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
16 changes: 13 additions & 3 deletions ndk-build/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct ApkConfig {
pub assets: Option<PathBuf>,
pub resources: Option<PathBuf>,
pub manifest: AndroidManifest,
pub disable_aapt_compression: bool,
}

impl ApkConfig {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 8da0967

Please sign in to comment.