Skip to content

Commit adac218

Browse files
authored
fix(android): check version code in release mode (#9898)
1 parent aa55e03 commit adac218

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": patch:enhance
3+
---
4+
5+
Check for Android version code before building the package in release mode.

core/tauri-build/src/mobile.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use anyhow::{Context, Result};
88
use semver::Version;
99
use tauri_utils::config::Config;
1010

11+
use crate::is_dev;
12+
1113
pub fn generate_gradle_files(project_dir: PathBuf, config: &Config) -> Result<()> {
1214
let gradle_settings_path = project_dir.join("tauri.settings.gradle");
1315
let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts");
@@ -57,7 +59,23 @@ dependencies {"
5759
if let Some(version_code) = config.bundle.android.version_code.as_ref() {
5860
app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
5961
} else if let Ok(version) = Version::parse(version) {
60-
let version_code = version.major * 1000000 + version.minor * 1000 + version.patch;
62+
let mut version_code = version.major * 1000000 + version.minor * 1000 + version.patch;
63+
64+
if is_dev() {
65+
version_code = version_code.clamp(1, 2100000000);
66+
}
67+
68+
if version_code == 0 {
69+
return Err(anyhow::anyhow!(
70+
"You must change the `version` in `tauri.conf.json`. The default value `0.0.0` is not allowed for Android package and must be at least `0.0.1`."
71+
));
72+
} else if version_code > 2100000000 {
73+
return Err(anyhow::anyhow!(
74+
"Invalid version code {}. Version code must be between 1 and 2100000000. You must change the `version` in `tauri.conf.json`.",
75+
version_code
76+
));
77+
}
78+
6179
app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
6280
}
6381
}

0 commit comments

Comments
 (0)