Skip to content

Commit 9a07c4a

Browse files
committed
Use gradle when the build target is Aab
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 bd2052f commit 9a07c4a

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() {
@@ -185,7 +190,7 @@ pub fn build(env: &BuildEnv) -> Result<()> {
185190
}
186191
}
187192

188-
if env.config().android().gradle {
193+
if env.target().android_gradle {
189194
crate::gradle::build(env, libraries, &out)?;
190195
runner.end_verbose_task();
191196
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;
66
use std::path::{Path, PathBuf};
77
use xcommon::Signer;
@@ -466,8 +466,18 @@ impl BuildTargetArgs {
466466
} else if store == Some(Store::Play) {
467467
Format::Aab
468468
} else {
469-
Format::platform_default(platform, opt, config.android().gradle)
469+
let user_wants_gradle = config.android().gradle.unwrap_or(false);
470+
Format::platform_default(platform, opt, user_wants_gradle)
470471
};
472+
473+
let android_gradle = config.android().gradle.unwrap_or(format == Format::Aab);
474+
475+
ensure!(
476+
// This fails if the format is Aab while `gradle == Some(false)`
477+
format != Format::Aab || android_gradle,
478+
"Android App Bundles (AABs) can currently only be built using `gradle`"
479+
);
480+
471481
let provisioning_profile = if let Some(profile) = self.provisioning_profile {
472482
anyhow::ensure!(
473483
profile.exists(),
@@ -492,6 +502,7 @@ impl BuildTargetArgs {
492502
signer,
493503
provisioning_profile,
494504
api_key,
505+
android_gradle,
495506
})
496507
}
497508
}
@@ -507,6 +518,7 @@ pub struct BuildTarget {
507518
signer: Option<Signer>,
508519
provisioning_profile: Option<Vec<u8>>,
509520
api_key: Option<PathBuf>,
521+
android_gradle: bool,
510522
}
511523

512524
impl BuildTarget {

0 commit comments

Comments
 (0)