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
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 committed Jun 5, 2022
1 parent 7e33384 commit f1121c0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions cargo-apk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Export the sole `NativeActivity` (through `android:exported="true"`) to allow it to be started by default if targeting Android S or higher. ([#242](https://github.com/rust-windowing/android-ndk-rs/pull/242))
- `cargo-apk` version can now be queried through `cargo apk version`. ([#218](https://github.com/rust-windowing/android-ndk-rs/pull/218))
- Environment variables from `.cargo/config.toml`'s `[env]` section are now propagated to the process environment. ([#249](https://github.com/rust-windowing/android-ndk-rs/pull/249))
- 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.8.2 (2021-11-22)

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 @@ -162,6 +162,7 @@ impl<'a> ApkBuilder<'a> {
assets,
resources,
manifest,
disable_aapt_compression: self.cmd.profile() == &Profile::Dev,
};
let apk = config.create_apk()?;

Expand Down
1 change: 1 addition & 0 deletions ndk-build/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Add `android:exported` attribute to the manifest's `Activity` element. ([#242](https://github.com/rust-windowing/android-ndk-rs/pull/242))
- Add `android:sharedUserId` attribute to the manifest's top-level `manifest` element. ([#252](https://github.com/rust-windowing/android-ndk-rs/pull/252))
- Add `queries` element to the manifest's top-level `manifest` element. ([#259](https://github.com/rust-windowing/android-ndk-rs/pull/259))
- **Breaking:** Add `disable_aapt_compression` field to `ApkConfig` to disable `aapt` compression. ([#283](https://github.com/rust-windowing/android-ndk-rs/pull/283))

# 0.4.3 (2021-11-22)

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 f1121c0

Please sign in to comment.