Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gradle when the build target is Aab #156

Draft
wants to merge 1 commit into
base: gradle-library-dependencies
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions xbuild/src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ pub fn build(env: &BuildEnv) -> Result<()> {
let bin_target = env.target().platform() != Platform::Android;
let has_lib = env.root_dir().join("src").join("lib.rs").exists();
if bin_target || has_lib {
if env.target().platform() == Platform::Android && env.config().android().gradle {
ensure!(
env.target().format() != Format::Aab || env.target().android_gradle,
"Android App Bundles (AABs) can currently only be built using `gradle`"
);

if env.target().platform() == Platform::Android && env.target().android_gradle {
crate::gradle::prepare(env)?;
}
for target in env.target().compile_targets() {
Expand Down Expand Up @@ -185,7 +190,7 @@ pub fn build(env: &BuildEnv) -> Result<()> {
}
}

if env.config().android().gradle {
if env.target().android_gradle {
crate::gradle::build(env, libraries, &out)?;
runner.end_verbose_task();
return Ok(());
Expand Down
4 changes: 3 additions & 1 deletion xbuild/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,10 @@ pub struct AndroidConfig {
pub manifest: AndroidManifest,
#[serde(default)]
pub dependencies: Vec<String>,
/// Defaults to [`false`], but uses [`true`] when the user builds a format that requires
/// `gradle` (i.e. [`Format::Aab`]).
#[serde(default)]
pub gradle: bool,
pub gradle: Option<bool>,
#[serde(default)]
pub wry: bool,
#[serde(default)]
Expand Down
16 changes: 14 additions & 2 deletions xbuild/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cargo::{Cargo, CargoBuild, CrateType};
use crate::config::Config;
use crate::devices::Device;
use anyhow::Result;
use anyhow::{ensure, Result};
use clap::Parser;
use std::path::{Path, PathBuf};
use xcommon::Signer;
Expand Down Expand Up @@ -466,8 +466,18 @@ impl BuildTargetArgs {
} else if store == Some(Store::Play) {
Format::Aab
} else {
Format::platform_default(platform, opt, config.android().gradle)
let user_wants_gradle = config.android().gradle.unwrap_or(false);
Format::platform_default(platform, opt, user_wants_gradle)
};

let android_gradle = config.android().gradle.unwrap_or(format == Format::Aab);

ensure!(
// This fails if the format is Aab while `gradle == Some(false)`
format != Format::Aab || android_gradle,
"Android App Bundles (AABs) can currently only be built using `gradle`"
);

let provisioning_profile = if let Some(profile) = self.provisioning_profile {
anyhow::ensure!(
profile.exists(),
Expand All @@ -492,6 +502,7 @@ impl BuildTargetArgs {
signer,
provisioning_profile,
api_key,
android_gradle,
})
}
}
Expand All @@ -507,6 +518,7 @@ pub struct BuildTarget {
signer: Option<Signer>,
provisioning_profile: Option<Vec<u8>>,
api_key: Option<PathBuf>,
android_gradle: bool,
}

impl BuildTarget {
Expand Down
Loading