-
Notifications
You must be signed in to change notification settings - Fork 0
feat(android): add auto_increment_version_code option for Android builds #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: qodo_claude_vs_qodo_base_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1
Are you sure you want to change the base?
Changes from all commits
e843f00
a440abf
a170b5d
1094c16
601b3f9
9e67cf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "tauri-cli": minor:feat | ||
| "@tauri-apps/cli": minor:feat | ||
| "tauri-build": minor:feat | ||
| "tauri-utils": minor:feat | ||
| --- | ||
|
|
||
| Add `tauri.conf.json > bundle > android > autoIncrementVersionCode` config option to automatically increment the Android version code. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ use crate::{ | |
| flock, | ||
| }, | ||
| interface::{AppInterface, Interface, Options as InterfaceOptions}, | ||
| mobile::{write_options, CliOptions, TargetDevice}, | ||
| mobile::{android::generate_tauri_properties, write_options, CliOptions, TargetDevice}, | ||
| ConfigValue, Error, Result, | ||
| }; | ||
| use clap::{ArgAction, Parser}; | ||
|
|
@@ -178,6 +178,12 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<BuiltApplica | |
| let mut env = env(options.ci)?; | ||
| configure_cargo(&mut env, &config)?; | ||
|
|
||
| generate_tauri_properties( | ||
| &config, | ||
| tauri_config.lock().unwrap().as_ref().unwrap(), | ||
| false, | ||
| )?; | ||
|
Comment on lines
+181
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. tauri_config.lock() uses unwrap The new Android build path uses unwrap() on a mutex lock and on an Option, which can panic and terminate the process. This violates the requirement to avoid panicking for fallible operations and to return/propagate errors via Result. Agent Prompt
|
||
|
|
||
| crate::build::setup(&interface, &mut build_options, tauri_config.clone(), true)?; | ||
|
|
||
| let installed_targets = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ use cargo_mobile2::{ | |
| util::prompt, | ||
| }; | ||
| use clap::{Parser, Subcommand}; | ||
| use semver::Version; | ||
| use std::{ | ||
| env::set_var, | ||
| fs::{create_dir, create_dir_all, read_dir, write}, | ||
|
|
@@ -620,3 +621,66 @@ fn configure_cargo(env: &mut Env, config: &AndroidConfig) -> Result<()> { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn generate_tauri_properties( | ||
| config: &AndroidConfig, | ||
| tauri_config: &TauriConfig, | ||
| dev: bool, | ||
| ) -> Result<()> { | ||
|
Comment on lines
+625
to
+629
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. generate_tauri_properties lacks docs A new pub fn generate_tauri_properties is introduced without Rust documentation comments. This violates the requirement to document public APIs for usability and generated docs. Agent Prompt
|
||
| let app_tauri_properties_path = config.project_dir().join("app").join("tauri.properties"); | ||
|
|
||
| let mut app_tauri_properties = Vec::new(); | ||
| if let Some(version) = tauri_config.version.as_ref() { | ||
| app_tauri_properties.push(format!("tauri.android.versionName={version}")); | ||
| if tauri_config.bundle.android.auto_increment_version_code { | ||
| let last_version_code = std::fs::read_to_string(&app_tauri_properties_path) | ||
| .ok() | ||
| .and_then(|content| { | ||
| content | ||
| .lines() | ||
| .find(|line| line.starts_with("tauri.android.versionCode=")) | ||
| .and_then(|line| line.split('=').nth(1)) | ||
| .and_then(|s| s.trim().parse::<u32>().ok()) | ||
| }); | ||
| let new_version_code = last_version_code.map(|v| v.saturating_add(1)).unwrap_or(1); | ||
| app_tauri_properties.push(format!("tauri.android.versionCode={new_version_code}")); | ||
|
Comment on lines
+635
to
+646
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4. Unbounded auto-increment versioncode With autoIncrementVersionCode=true, generate_tauri_properties increments the previous versionCode without enforcing the documented maximum (2,100,000,000). This can create an out-of-policy versionCode (Play Store rejection) and can eventually exceed Kotlin/Gradle Int parsing limits, breaking the build. Agent Prompt
Comment on lines
+636
to
+646
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5. Auto-increment resets to 1 If tauri.properties is missing/unreadable or the tauri.android.versionCode= line can’t be parsed, autoIncrementVersionCode silently sets versionCode to 1. This can decrease the versionCode relative to prior releases and block upgrades/publishing without any warning. Agent Prompt
|
||
| } else if let Some(version_code) = tauri_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 mut version_code = version.major * 1000000 + version.minor * 1000 + version.patch; | ||
|
|
||
| if version_code == 0 { | ||
| crate::error::bail!( | ||
| "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`." | ||
| ); | ||
| } else if version_code > 2100000000 { | ||
| crate::error::bail!( | ||
| "Invalid version code {}. Version code must be between 1 and 2100000000. You must change the `version` in `tauri.conf.json`.", | ||
| version_code | ||
| ); | ||
| } | ||
|
|
||
| if dev { | ||
| version_code = version_code.clamp(1, 2100000000); | ||
| } | ||
|
|
||
| app_tauri_properties.push(format!("tauri.android.versionCode={version_code}")); | ||
| } | ||
| } | ||
|
|
||
| if !app_tauri_properties.is_empty() { | ||
| let app_tauri_properties_content = format!( | ||
| "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n{}", | ||
| app_tauri_properties.join("\n") | ||
| ); | ||
| if std::fs::read_to_string(&app_tauri_properties_path) | ||
| .map(|o| app_tauri_properties_content != o) | ||
| .unwrap_or(true) | ||
| { | ||
| write(&app_tauri_properties_path, app_tauri_properties_content) | ||
| .context("failed to write tauri.properties")?; | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. Missing android version properties
🐞 Bug✓ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools