Skip to content

Commit 2ba3e40

Browse files
authored
Use gradle when the build target is Aab (#156)
Instead of explicitly requiring `gradle: true` in the manifest, enable it by default when the (implicit or explicit!) output package format is `Aab` for convenience, as there is currently no way to select the `gradle` backend via command line parameters and hardcoding it in `manifest.yaml` makes it inconvenient to build `Apk`s with the "native" builtin backend. Also insert validation in case the user explicitly inserts `gradle: false` but tries to build `Aab`s. The default for releases is still `Aab` if there is an explicit `gradle: true`, but an `Apk` is built otherwise.
1 parent ecb398e commit 2ba3e40

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

xbuild/src/command/build.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ pub fn build(env: &BuildEnv) -> Result<()> {
2929
let bin_target = env.target().platform() != Platform::Android;
3030
let has_lib = env.root_dir().join("src").join("lib.rs").exists();
3131
if bin_target || has_lib {
32-
if env.target().platform() == Platform::Android && env.config().android().gradle {
32+
ensure!(
33+
env.target().format() != Format::Aab || env.target().android_gradle,
34+
"Android App Bundles (AABs) can currently only be built using `gradle`"
35+
);
36+
37+
if env.target().platform() == Platform::Android && env.target().android_gradle {
3338
crate::gradle::prepare(env)?;
3439
}
3540
for target in env.target().compile_targets() {
@@ -190,7 +195,7 @@ pub fn build(env: &BuildEnv) -> Result<()> {
190195
}
191196
}
192197

193-
if env.config().android().gradle {
198+
if env.target().android_gradle {
194199
crate::gradle::build(env, libraries, &out)?;
195200
runner.end_verbose_task();
196201
return Ok(());

xbuild/src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,10 @@ pub struct AndroidConfig {
430430
pub manifest: AndroidManifest,
431431
#[serde(default)]
432432
pub dependencies: Vec<String>,
433+
/// Defaults to [`false`], but uses [`true`] when the user builds a format that requires
434+
/// `gradle` (i.e. [`Format::Aab`]).
433435
#[serde(default)]
434-
pub gradle: bool,
436+
pub gradle: Option<bool>,
435437
#[serde(default)]
436438
pub wry: bool,
437439
#[serde(default)]

xbuild/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::cargo::{Cargo, CargoBuild, CrateType};
22
use crate::config::Config;
33
use crate::devices::Device;
4-
use anyhow::Result;
4+
use anyhow::{ensure, Result};
55
use clap::{Parser, ValueEnum};
66
use std::path::{Path, PathBuf};
77
use xcommon::Signer;
@@ -386,8 +386,18 @@ impl BuildTargetArgs {
386386
} else if store == Some(Store::Play) {
387387
Format::Aab
388388
} else {
389-
Format::platform_default(platform, opt, config.android().gradle)
389+
let user_wants_gradle = config.android().gradle.unwrap_or(false);
390+
Format::platform_default(platform, opt, user_wants_gradle)
390391
};
392+
393+
let android_gradle = config.android().gradle.unwrap_or(format == Format::Aab);
394+
395+
ensure!(
396+
// This fails if the format is Aab while `gradle == Some(false)`
397+
format != Format::Aab || android_gradle,
398+
"Android App Bundles (AABs) can currently only be built using `gradle`"
399+
);
400+
391401
let provisioning_profile = if let Some(profile) = self.provisioning_profile {
392402
anyhow::ensure!(
393403
profile.exists(),
@@ -412,6 +422,7 @@ impl BuildTargetArgs {
412422
signer,
413423
provisioning_profile,
414424
api_key,
425+
android_gradle,
415426
})
416427
}
417428
}
@@ -427,6 +438,7 @@ pub struct BuildTarget {
427438
signer: Option<Signer>,
428439
provisioning_profile: Option<Vec<u8>>,
429440
api_key: Option<PathBuf>,
441+
android_gradle: bool,
430442
}
431443

432444
impl BuildTarget {

0 commit comments

Comments
 (0)