Skip to content

Commit 7d5bd44

Browse files
fontlosjkelleyrtp
andauthored
feat(cli): add bundle.android config to build and sign the apk file in release mode (#4062)
* feat(cli): add `bundle.android` config to build and sign the apk file in release mode Add this to `Dioxus.toml` ```toml [bundle.android] jks_file = "path/to/jks file relative to Dioxus.toml" jks_password = "jks_password " key_alias = "key_alias" key_password = "key_password " ``` When release flag is enabled and this configuration exists at the same time, use `gradlew assembleRelease` build and sign apk file * fix merge conflict * only run assembleRelease when bundle exists --------- Co-authored-by: Jonathan Kelley <[email protected]>
1 parent ad63d52 commit 7d5bd44

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

packages/cli/assets/android/gen/app/build.gradle.kts.hbs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ android {
1313
versionCode = 1
1414
versionName = "1.0"
1515
}
16+
{{#if android_bundle}}
17+
signingConfigs {
18+
create("release") {
19+
storeFile = file("../../../../../../../{{ android_bundle.jks_file }}")
20+
storePassword = "{{ android_bundle.jks_password }}"
21+
keyAlias = "{{ android_bundle.key_alias }}"
22+
keyPassword = "{{ android_bundle.key_password }}"
23+
}
24+
}
25+
{{/if}}
1626
buildTypes {
1727
getByName("debug") {
1828
isDebuggable = true
@@ -27,7 +37,10 @@ android {
2737
}
2838
getByName("release") {
2939
isMinifyEnabled = true
30-
proguardFiles(
40+
{{#if android_bundle}}
41+
signingConfig = signingConfigs.getByName("release")
42+
{{/if}}
43+
proguardFiles(
3144
*fileTree(".") { include("**/*.pro") }
3245
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
3346
.toList().toTypedArray()

packages/cli/src/build/request.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,10 +2271,12 @@ session_cache_dir: {}"#,
22712271
struct AndroidHandlebarsObjects {
22722272
application_id: String,
22732273
app_name: String,
2274+
android_bundle: Option<crate::AndroidSettings>,
22742275
}
22752276
let hbs_data = AndroidHandlebarsObjects {
22762277
application_id: self.full_mobile_app_name(),
22772278
app_name: self.bundled_app_name(),
2279+
android_bundle: self.config.bundle.android.clone(),
22782280
};
22792281
let hbs = handlebars::Handlebars::new();
22802282

@@ -3164,8 +3166,15 @@ session_cache_dir: {}"#,
31643166
if let Platform::Android = self.platform {
31653167
ctx.status_running_gradle();
31663168

3169+
// When the build mode is set to release and there is an Android signature configuration, use assembleRelease
3170+
let build_type = if self.release && self.config.bundle.android.is_some() {
3171+
"assembleRelease"
3172+
} else {
3173+
"assembleDebug"
3174+
};
3175+
31673176
let output = Command::new(self.gradle_exe()?)
3168-
.arg("assembleDebug")
3177+
.arg(build_type)
31693178
.current_dir(self.root_dir())
31703179
.output()
31713180
.await?;

packages/cli/src/config/bundle.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub(crate) struct BundleConfig {
1616
pub(crate) deb: Option<DebianSettings>,
1717
pub(crate) macos: Option<MacOsSettings>,
1818
pub(crate) windows: Option<WindowsSettings>,
19+
pub(crate) android: Option<AndroidSettings>,
1920
}
2021

2122
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
@@ -185,6 +186,15 @@ impl Default for WebviewInstallMode {
185186
}
186187
}
187188

189+
// Because all four fields must appear at the same time, there is no need for an Option
190+
#[derive(Debug, Clone, Serialize, Deserialize)]
191+
pub(crate) struct AndroidSettings {
192+
pub(crate) jks_file: PathBuf,
193+
pub(crate) jks_password: String,
194+
pub(crate) key_alias: String,
195+
pub(crate) key_password: String,
196+
}
197+
188198
#[derive(Debug, Clone, Serialize, Deserialize)]
189199
pub struct CustomSignCommandSettings {
190200
/// The command to run to sign the binary.

0 commit comments

Comments
 (0)