|
@@ -5,10 +5,13 @@
|
|
|
use std::{fs::write, path::PathBuf};
|
|
|
|
|
|
use anyhow::{Context, Result};
|
|
|
+use semver::Version;
|
|
|
+use tauri_utils::config::Config;
|
|
|
|
|
|
-pub fn generate_gradle_files(project_dir: PathBuf) -> Result<()> {
|
|
|
+pub fn generate_gradle_files(project_dir: PathBuf, config: &Config) -> Result<()> {
|
|
|
let gradle_settings_path = project_dir.join("tauri.settings.gradle");
|
|
|
let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts");
|
|
|
+ let app_tauri_properties_path = project_dir.join("app").join("tauri.properties");
|
|
|
|
|
|
let mut gradle_settings =
|
|
|
"// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n".to_string();
|
|
@@ -16,6 +19,7 @@ pub fn generate_gradle_files(project_dir: PathBuf) -> Result<()> {
|
|
|
val implementation by configurations
|
|
|
dependencies {"
|
|
|
.to_string();
|
|
|
+ let mut app_tauri_properties = Vec::new();
|
|
|
|
|
|
for (env, value) in std::env::vars_os() {
|
|
|
let env = env.to_string_lossy();
|
|
@@ -48,13 +52,40 @@ dependencies {"
|
|
|
|
|
|
app_build_gradle.push_str("\n}");
|
|
|
|
|
|
+ if let Some(version) = config.version.as_ref() {
|
|
|
+ app_tauri_properties.push(format!("tauri.android.versionName={}", version));
|
|
|
+ if let Some(version_code) = config.bundle.android.version_code.as_ref() {
|
|
|
+ app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
|
|
|
+ } else if let Ok(version) = Version::parse(version) {
|
|
|
+ let version_code = version.major * 1000000 + version.minor * 1000 + version.patch;
|
|
|
+ app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
write(&gradle_settings_path, gradle_settings).context("failed to write tauri.settings.gradle")?;
|
|
|
|
|
|
write(&app_build_gradle_path, app_build_gradle)
|
|
|
.context("failed to write tauri.build.gradle.kts")?;
|
|
|
|
|
|
+ if !app_tauri_properties.is_empty() {
|
|
|
+ write(
|
|
|
+ &app_tauri_properties_path,
|
|
|
+ format!(
|
|
|
+ "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n{}",
|
|
|
+ app_tauri_properties.join("\n")
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ .context("failed to write tauri.properties")?;
|
|
|
+ }
|
|
|
+
|
|
|
println!("cargo:rerun-if-changed={}", gradle_settings_path.display());
|
|
|
println!("cargo:rerun-if-changed={}", app_build_gradle_path.display());
|
|
|
+ if !app_tauri_properties.is_empty() {
|
|
|
+ println!(
|
|
|
+ "cargo:rerun-if-changed={}",
|
|
|
+ app_tauri_properties_path.display()
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
Ok(())
|
|
|
}
|