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 <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
ad63d529fd
commit
7d5bd44791
3 files changed
+34
-2
No files matched your search
@@ -13,6 +13,16 @@ android {
|
|||||||
versionCode = 1
|
versionCode = 1
|
||||||
versionName = "1.0"
|
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 {
|
buildTypes {
|
||||||
getByName("debug") {
|
getByName("debug") {
|
||||||
isDebuggable = true
|
isDebuggable = true
|
||||||
@@ -27,7 +37,10 @@ android {
|
|||||||
}
|
}
|
||||||
getByName("release") {
|
getByName("release") {
|
||||||
isMinifyEnabled = true
|
isMinifyEnabled = true
|
||||||
proguardFiles(
|
{{#if android_bundle}}
|
||||||
|
signingConfig = signingConfigs.getByName("release")
|
||||||
|
{{/if}}
|
||||||
|
proguardFiles(
|
||||||
*fileTree(".") { include("**/*.pro") }
|
*fileTree(".") { include("**/*.pro") }
|
||||||
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
|
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
|
||||||
.toList().toTypedArray()
|
.toList().toTypedArray()
|
||||||
|
|||||||
@@ -2271,10 +2271,12 @@ session_cache_dir: {}"#,
|
|||||||
struct AndroidHandlebarsObjects {
|
struct AndroidHandlebarsObjects {
|
||||||
application_id: String,
|
application_id: String,
|
||||||
app_name: String,
|
app_name: String,
|
||||||
|
android_bundle: Option<crate::AndroidSettings>,
|
||||||
}
|
}
|
||||||
let hbs_data = AndroidHandlebarsObjects {
|
let hbs_data = AndroidHandlebarsObjects {
|
||||||
application_id: self.full_mobile_app_name(),
|
application_id: self.full_mobile_app_name(),
|
||||||
app_name: self.bundled_app_name(),
|
app_name: self.bundled_app_name(),
|
||||||
|
android_bundle: self.config.bundle.android.clone(),
|
||||||
};
|
};
|
||||||
let hbs = handlebars::Handlebars::new();
|
let hbs = handlebars::Handlebars::new();
|
||||||
|
|
||||||
@@ -3164,8 +3166,15 @@ session_cache_dir: {}"#,
|
|||||||
if let Platform::Android = self.platform {
|
if let Platform::Android = self.platform {
|
||||||
ctx.status_running_gradle();
|
ctx.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.release && self.config.bundle.android.is_some() {
|
||||||
|
"assembleRelease"
|
||||||
|
} else {
|
||||||
|
"assembleDebug"
|
||||||
|
};
|
||||||
|
|
||||||
let output = Command::new(self.gradle_exe()?)
|
let output = Command::new(self.gradle_exe()?)
|
||||||
.arg("assembleDebug")
|
.arg(build_type)
|
||||||
.current_dir(self.root_dir())
|
.current_dir(self.root_dir())
|
||||||
.output()
|
.output()
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub(crate) struct BundleConfig {
|
|||||||
pub(crate) deb: Option<DebianSettings>,
|
pub(crate) deb: Option<DebianSettings>,
|
||||||
pub(crate) macos: Option<MacOsSettings>,
|
pub(crate) macos: Option<MacOsSettings>,
|
||||||
pub(crate) windows: Option<WindowsSettings>,
|
pub(crate) windows: Option<WindowsSettings>,
|
||||||
|
pub(crate) android: Option<AndroidSettings>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
@@ -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)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct CustomSignCommandSettings {
|
pub struct CustomSignCommandSettings {
|
||||||
/// The command to run to sign the binary.
|
/// The command to run to sign the binary.
|
||||||
|
|||||||
Reference in new issue
Block a user