feat(android): add auto_increment_version_code option for Android builds - #27
Conversation
Code Review by Qodo
1. tauri_config double unwrap()
|
| generate_tauri_properties( | ||
| &config, | ||
| tauri_config.lock().unwrap().as_ref().unwrap(), | ||
| false, | ||
| )?; |
There was a problem hiding this comment.
1. tauri_config double unwrap() 📘 Rule violation ⛯ Reliability
• New code calls tauri_config.lock().unwrap().as_ref().unwrap(), which can panic at runtime if the mutex is poisoned or the inner value is None. • This violates the requirement to avoid panics/unwrap() for fallible operations and instead propagate errors via Result. • A panic here would crash the CLI during Android build/dev flows rather than providing actionable error context.
Agent prompt
## Issue description
Android build/dev code uses `unwrap()` on `tauri_config.lock()` and on the inner `Option`, which can panic and crash the CLI.
## Issue Context
Per compliance requirements, fallible operations should not panic; they should return `Result` with meaningful context.
## Fix Focus Areas
- crates/tauri-cli/src/mobile/android/build.rs[181-185]
- crates/tauri-cli/src/mobile/android/dev.rs[274-274]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| pub fn generate_tauri_properties( | ||
| config: &AndroidConfig, | ||
| tauri_config: &TauriConfig, | ||
| dev: bool, | ||
| ) -> Result<()> { |
There was a problem hiding this comment.
2. generate_tauri_properties undocumented 📘 Rule violation ✧ Quality
• A new public API pub fn generate_tauri_properties(...) was introduced without any /// documentation comments. • This violates the requirement that public functions/methods include documentation explaining purpose, parameters, and behavior. • Lack of docs makes the new behavior (including auto-increment semantics) harder to use correctly.
Agent prompt
## Issue description
The new public function `generate_tauri_properties` lacks required documentation comments.
## Issue Context
Public APIs must be documented so consumers understand behavior and configuration implications.
## 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
| 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.
3. Auto-increment exceeds max 🐞 Bug ✓ Correctness
• autoIncrementVersionCode increments the previous versionCode read from tauri.properties but never validates/clamps to the documented maximum (2,100,000,000). • Once a repo reaches versionCode=2100000000, the next build will write 2100000001 (still a valid u32) which violates the schema/Play Store constraint and can cause Gradle/Play publishing failures.
Agent prompt
### Issue description
`autoIncrementVersionCode` increments the last persisted `versionCode` from `tauri.properties`, but does not enforce the documented maximum of 2,100,000,000. This can write `versionCode` values that Gradle/Play Store reject.
### Issue Context
- Schema documents `versionCode` maximum: 2,100,000,000.
- Current logic uses `saturating_add(1)` which only prevents `u32` overflow (up to `u32::MAX`), not Android’s max.
### Fix Focus Areas
- crates/tauri-cli/src/mobile/android/mod.rs[635-646]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| pub fn generate_gradle_files(project_dir: PathBuf) -> 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"); | ||
|
|
There was a problem hiding this comment.
4. Tauri.properties generation regression 🐞 Bug ⛯ Reliability
• tauri-build no longer generates app/tauri.properties, but the Android template uses that file to set versionCode/versionName. • If developers build the generated Android project directly via Gradle/Android Studio (without running tauri-cli Android build/dev first), Gradle will fall back to default versionCode=1 and versionName=1.0, and the values won’t be kept in sync with tauri.conf.json by tauri-build anymore.
Agent prompt
### Issue description
Android version metadata (`versionCode`/`versionName`) is read from `app/tauri.properties` in the Android template. This PR removes `tauri.properties` generation from `tauri-build` and only generates it in tauri-cli Android build/dev flows, which can break or change behavior for direct Gradle/Android Studio builds.
### Issue Context
- `build.gradle.kts` defaults to versionCode=1/versionName=1.0 if `tauri.properties` does not exist.
- After this change, `tauri-build` no longer produces `tauri.properties` at all.
### Fix Focus Areas
- crates/tauri-build/src/mobile.rs[10-62]
- crates/tauri-cli/templates/mobile/android/app/build.gradle.kts[11-28]
- crates/tauri-cli/src/mobile/android/build.rs[178-188]
- crates/tauri-cli/src/mobile/android/dev.rs[268-276]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#1