Skip to content

feat: add bundle.android config to build and sign the apk file in release mode #3906

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

Closed
wants to merge 3 commits into from
Closed
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
15 changes: 14 additions & 1 deletion packages/cli/assets/android/gen/app/build.gradle.kts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ android {
versionCode = 1
versionName = "1.0"
}
{{#if android_bundle}}
signingConfigs {
create("release") {
storeFile = file("../../../../../../../{{ android_bundle.jks_file }}")
storePassword = "{{ android_bundle.jks_password }}"
keyAlias = "{{ android_bundle.key_alias }}"
keyPassword = "{{ android_bundle.key_password }}"
}
}
{{/if}}
buildTypes {
getByName("debug") {
isDebuggable = true
Expand All @@ -27,7 +37,10 @@ android {
}
getByName("release") {
isMinifyEnabled = true
proguardFiles(
{{#if android_bundle}}
signingConfig = signingConfigs.getByName("release")
{{/if}}
proguardFiles(
*fileTree(".") { include("**/*.pro") }
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
.toList().toTypedArray()
Expand Down
10 changes: 9 additions & 1 deletion packages/cli/src/build/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,16 @@ impl AppBundle {
if let Platform::Android = self.build.build.platform() {
self.build.status_running_gradle();

// When the build mode is set to release and there is an Android signature configuration, use assembleRelease
let build_type =
if self.build.build.release && self.build.krate.config.bundle.android.is_some() {
"assembleRelease"
} else {
"assembleDebug"
};

let output = Command::new(self.gradle_exe()?)
.arg("assembleDebug")
.arg(build_type)
.current_dir(self.build.root_dir())
.stderr(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/build/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,12 @@ impl BuildRequest {
struct HbsTypes {
application_id: String,
app_name: String,
android_bundle: Option<crate::AndroidSettings>,
}
let hbs_data = HbsTypes {
application_id: self.krate.full_mobile_app_name(),
app_name: self.krate.bundled_app_name(),
android_bundle: self.krate.config.bundle.android.clone(),
};

// Top-level gradle config
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/config/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) struct BundleConfig {
pub(crate) deb: Option<DebianSettings>,
pub(crate) macos: Option<MacOsSettings>,
pub(crate) windows: Option<WindowsSettings>,
pub(crate) android: Option<AndroidSettings>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -185,6 +186,15 @@ impl Default for WebviewInstallMode {
}
}

/// Because all four fields must appear at the same time, there is no need for an Option
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct AndroidSettings {
pub(crate) jks_file: PathBuf,
pub(crate) jks_password: String,
pub(crate) key_alias: String,
pub(crate) key_password: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomSignCommandSettings {
/// The command to run to sign the binary.
Expand Down