feat(android): add auto_increment_version_code option for Android builds - #40
Conversation
Review Summary by QodoAdd autoIncrementVersionCode option for Android version management
WalkthroughsDescription• Add autoIncrementVersionCode config option for Android builds • Automatically increment version code on each build from properties file • Refactor version code generation logic into dedicated function • Move properties generation from build-time to CLI commands Diagramflowchart LR
A["AndroidConfig"] -->|"new field"| B["auto_increment_version_code"]
C["CLI Build/Dev"] -->|"calls"| D["generate_tauri_properties"]
D -->|"reads last code"| E["tauri.properties"]
D -->|"increments or uses"| F["version_code/semver"]
D -->|"writes"| E
G["tauri-build"] -->|"simplified"| H["generate_gradle_files"]
File Changes1. crates/tauri-utils/src/config.rs
|
Code Review by Qodo
1. generate_tauri_properties lacks docs
|
| pub fn generate_tauri_properties( | ||
| config: &AndroidConfig, | ||
| tauri_config: &TauriConfig, | ||
| dev: bool, | ||
| ) -> Result<()> { |
There was a problem hiding this comment.
1. generate_tauri_properties lacks docs 📘 Rule violation ✓ Correctness
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
## Issue description
A new public function `generate_tauri_properties` was added without Rust doc comments (`///`). Public APIs must be documented.
## Issue Context
This function is `pub` and will appear in generated documentation; add docs describing what it generates, what inputs mean (`config`, `tauri_config`, `dev`), and key behavior (auto-increment logic, reading/writing `tauri.properties`).
## Fix Focus Areas
- crates/tauri-cli/src/mobile/android/mod.rs[625-629]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| generate_tauri_properties( | ||
| &config, | ||
| tauri_config.lock().unwrap().as_ref().unwrap(), | ||
| false, | ||
| )?; |
There was a problem hiding this comment.
2. tauri_config.lock() uses unwrap 📘 Rule violation ⛯ Reliability
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
## Issue description
New code in Android build uses `tauri_config.lock().unwrap().as_ref().unwrap()`, which can panic (poisoned mutex / missing config). Compliance requires returning/propagating errors as `Result` instead of panicking.
## Issue Context
`generate_tauri_properties` already returns `Result<()>`, so callers can (and should) propagate lock/option access failures via `?` and meaningful errors rather than `unwrap()`.
## Fix Focus Areas
- crates/tauri-cli/src/mobile/android/build.rs[181-185]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| if let Some(project_dir) = env::var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) { | ||
| mobile::generate_gradle_files(project_dir, &config)?; | ||
| mobile::generate_gradle_files(project_dir)?; | ||
| } |
There was a problem hiding this comment.
3. Missing android version properties 🐞 Bug ✓ Correctness
tauri-build::try_build no longer generates app/tauri.properties, so Android builds that don’t run tauri-cli’s generate_tauri_properties will ignore tauri.conf.json version/versionCode and fall back to the Gradle template defaults (1/1.0). This silently produces wrong Android versionCode/versionName in those build flows.
Agent Prompt
### Issue description
Android versionCode/versionName are sourced from `app/tauri.properties` in the Android Gradle template. This PR removed `tauri.properties` generation from `tauri-build`, making correct versioning dependent on tauri-cli calling `generate_tauri_properties`, which does not cover non-CLI build flows.
### Issue Context
`tauri_build::try_build` still parses the Tauri config and still runs during Cargo build scripts, but now only writes `tauri.settings.gradle` and `tauri.build.gradle.kts`. The Gradle template defaults to versionCode=1/versionName=1.0 when `tauri.properties` is missing.
### Fix Focus Areas
- crates/tauri-build/src/lib.rs[473-503]
- crates/tauri-build/src/mobile.rs[10-62]
- crates/tauri-cli/templates/mobile/android/app/build.gradle.kts[11-28]
### Implementation direction
- Reintroduce `tauri.properties` generation in `tauri-build` using the parsed `Config` (including the new `auto_increment_version_code` behavior), or
- Add a `tauri-build` helper (e.g., `mobile::generate_tauri_properties(project_dir, config, dev)`), called from `try_build()` when `TAURI_ANDROID_PROJECT_PATH` is present.
- Ensure behavior matches the documented limits and dev/release expectations.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| 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}")); |
There was a problem hiding this comment.
4. Unbounded auto-increment versioncode 🐞 Bug ✓ Correctness
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
### Issue description
`autoIncrementVersionCode` increments versionCode without validating the new value against the documented maximum (2,100,000,000) and without considering Gradle/Kotlin `Int` parsing constraints.
### Issue Context
The value is written into `app/tauri.properties`, then the Android Gradle template reads it via `.toInt()`.
### Fix Focus Areas
- crates/tauri-cli/src/mobile/android/mod.rs[635-646]
- crates/tauri-utils/src/config.rs[2917-2931]
- crates/tauri-cli/templates/mobile/android/app/build.gradle.kts[21-28]
### Implementation direction
- Parse last_version_code as `u32`.
- If last_version_code >= 2_100_000_000, return an error explaining the limit and how to reset/override.
- Use `checked_add(1)` instead of `saturating_add(1)`.
- Optionally also reject values > `i32::MAX` (2_147_483_647) because Gradle uses `toInt()`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| 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}")); |
There was a problem hiding this comment.
5. Auto-increment resets to 1 🐞 Bug ⛯ Reliability
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
### Issue description
`autoIncrementVersionCode` silently falls back to versionCode=1 when `tauri.properties` is missing/unreadable/malformed. This is especially likely because the Android template ignores `tauri.properties` by default.
### Issue Context
Silent resets can cause non-monotonic versionCode and publishing/update failures.
### Fix Focus Areas
- crates/tauri-cli/src/mobile/android/mod.rs[636-646]
- crates/tauri-cli/templates/mobile/android/app/.gitignore[4-6]
### Implementation direction
- If `tauri.properties` is missing and auto-increment is enabled:
- Either: bail with a clear error telling the user to commit/unignore the file or set `bundle.android.versionCode` explicitly.
- Or: initialize from `bundle.android.version_code` if present, else from semver-derived versionCode, then write that value.
- If file exists but is unreadable/unparseable: return an error (don’t swallow with `.ok()`).
- Consider emitting a log message describing the chosen versionCode source.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#1