|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | // SPDX-License-Identifier: MIT |
4 | 4 |
|
5 | | -use std::{fs::write, path::PathBuf}; |
| 5 | +use std::path::PathBuf; |
6 | 6 |
|
7 | 7 | use anyhow::{Context, Result}; |
8 | | -use semver::Version; |
9 | | -use tauri_utils::{config::Config, write_if_changed}; |
| 8 | +use tauri_utils::write_if_changed; |
10 | 9 |
|
11 | | -use crate::is_dev; |
12 | | - |
13 | | -pub fn generate_gradle_files(project_dir: PathBuf, config: &Config) -> Result<()> { |
| 10 | +pub fn generate_gradle_files(project_dir: PathBuf) -> Result<()> { |
14 | 11 | let gradle_settings_path = project_dir.join("tauri.settings.gradle"); |
15 | 12 | let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts"); |
16 | | - let app_tauri_properties_path = project_dir.join("app").join("tauri.properties"); |
17 | 13 |
|
18 | 14 | let mut gradle_settings = |
19 | 15 | "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n".to_string(); |
20 | 16 | let mut app_build_gradle = "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. |
21 | 17 | val implementation by configurations |
22 | 18 | dependencies {" |
23 | 19 | .to_string(); |
24 | | - let mut app_tauri_properties = Vec::new(); |
25 | 20 |
|
26 | 21 | for (env, value) in std::env::vars_os() { |
27 | 22 | let env = env.to_string_lossy(); |
@@ -54,61 +49,15 @@ dependencies {" |
54 | 49 |
|
55 | 50 | app_build_gradle.push_str("\n}"); |
56 | 51 |
|
57 | | - if let Some(version) = config.version.as_ref() { |
58 | | - app_tauri_properties.push(format!("tauri.android.versionName={version}")); |
59 | | - if let Some(version_code) = config.bundle.android.version_code.as_ref() { |
60 | | - app_tauri_properties.push(format!("tauri.android.versionCode={version_code}")); |
61 | | - } else if let Ok(version) = Version::parse(version) { |
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 | | - |
79 | | - app_tauri_properties.push(format!("tauri.android.versionCode={version_code}")); |
80 | | - } |
81 | | - } |
82 | | - |
83 | 52 | // Overwrite only if changed to not trigger rebuilds |
84 | 53 | write_if_changed(&gradle_settings_path, gradle_settings) |
85 | 54 | .context("failed to write tauri.settings.gradle")?; |
86 | 55 |
|
87 | 56 | write_if_changed(&app_build_gradle_path, app_build_gradle) |
88 | 57 | .context("failed to write tauri.build.gradle.kts")?; |
89 | 58 |
|
90 | | - if !app_tauri_properties.is_empty() { |
91 | | - let app_tauri_properties_content = format!( |
92 | | - "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n{}", |
93 | | - app_tauri_properties.join("\n") |
94 | | - ); |
95 | | - if std::fs::read_to_string(&app_tauri_properties_path) |
96 | | - .map(|o| o != app_tauri_properties_content) |
97 | | - .unwrap_or(true) |
98 | | - { |
99 | | - write(&app_tauri_properties_path, app_tauri_properties_content) |
100 | | - .context("failed to write tauri.properties")?; |
101 | | - } |
102 | | - } |
103 | | - |
104 | 59 | println!("cargo:rerun-if-changed={}", gradle_settings_path.display()); |
105 | 60 | println!("cargo:rerun-if-changed={}", app_build_gradle_path.display()); |
106 | | - if !app_tauri_properties.is_empty() { |
107 | | - println!( |
108 | | - "cargo:rerun-if-changed={}", |
109 | | - app_tauri_properties_path.display() |
110 | | - ); |
111 | | - } |
112 | 61 |
|
113 | 62 | Ok(()) |
114 | 63 | } |
0 commit comments