feat(android): add auto_increment_version_code option for Android builds #1
Conversation
📝 WalkthroughWalkthroughThis pull request adds automatic Android version code incrementation functionality to Tauri. A new configuration option Changes
Sequence Diagram(s)sequenceDiagram
actor Dev as Developer
participant BuildCLI as Android Build/Dev CLI
participant PropGen as generate_tauri_properties
participant Config as Config Layer
participant FileIO as File I/O
participant GradleGen as Gradle Generation
Dev->>BuildCLI: Initiate build/dev
BuildCLI->>Config: Load tauri config
BuildCLI->>PropGen: generate_tauri_properties(config, tauri_config, dev_mode)
PropGen->>Config: Extract version & autoIncrement setting
PropGen->>FileIO: Read current tauri.properties (if exists)
FileIO-->>PropGen: Existing versionCode
PropGen->>PropGen: Compute versionName from semver
PropGen->>PropGen: Calculate versionCode (increment if enabled)
PropGen->>PropGen: Validate bounds & clamp if dev mode
PropGen->>FileIO: Write tauri.properties
FileIO-->>PropGen: Write complete
PropGen-->>BuildCLI: Properties generated
BuildCLI->>GradleGen: generate_gradle_files(project_dir)
GradleGen->>FileIO: Generate gradle configs
FileIO-->>GradleGen: Complete
GradleGen-->>BuildCLI: Gradle files ready
BuildCLI-->>Dev: Build/dev ready
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@crates/tauri-cli/src/mobile/android/dev.rs`:
- Around line 274-275: The auto-increment logic in generate_tauri_properties is
ignoring the dev flag and increments versionCode during dev runs; update the
condition that checks autoIncrementVersionCode/versionCode (the block around the
auto-increment logic in generate_tauri_properties) to also require that dev is
false (i.e., only auto-increment when !dev), so calls like
generate_tauri_properties(..., true) from the dev flow will not bump versionCode
during development.
In `@crates/tauri-cli/src/mobile/android/mod.rs`:
- Around line 635-648: The auto-increment branch should honor the dev flag and
clamp version codes to Android's max; change the logic around
tauri_config.bundle.android.auto_increment_version_code to first check
tauri_config.build.dev and, if dev is true, use last_version_code.unwrap_or(1)
without incrementing, otherwise compute new_version_code =
last_version_code.map(|v| v.saturating_add(1)).unwrap_or(1) and then clamp it to
a constant MAX_VERSION_CODE = 2_100_000_000 (e.g. new_version_code =
std::cmp::min(new_version_code, MAX_VERSION_CODE)); also validate/clamp the
explicit tauri_config.bundle.android.version_code path so the pushed value
(app_tauri_properties.push(...)) is never greater than MAX_VERSION_CODE and
always uses the clamped numeric value rather than the raw input.
In `@crates/tauri-schema-generator/schemas/config.schema.json`:
- Around line 3832-3834: Update the user-facing description for the
autoIncrementVersionCode schema entry to use the camelCase field name
"versionCode" instead of "version_code"; locate the "autoIncrementVersionCode"
property in the JSON schema and edit its "description" text to replace any
occurrences of "version_code" with "versionCode" while keeping the rest of the
explanatory text and default unchanged.
| generate_tauri_properties(config, tauri_config.lock().unwrap().as_ref().unwrap(), true)?; | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check the generate_tauri_properties function signature and its implementation
rg -n -B 2 -A 30 'fn generate_tauri_properties' crates/tauri-cli/src/mobile/android/mod.rsRepository: agentic-review-benchmarks/tauri-combined-coderabbit
Length of output: 1782
🏁 Script executed:
#!/bin/bash
# Check the actual call to generate_tauri_properties in dev.rs to see what parameters are passed
rg -n -B 3 -A 3 'generate_tauri_properties' crates/tauri-cli/src/mobile/android/dev.rsRepository: agentic-review-benchmarks/tauri-combined-coderabbit
Length of output: 673
🏁 Script executed:
#!/bin/bash
# Get the exact lines mentioned in the review (634-643) from mod.rs
sed -n '634,643p' crates/tauri-cli/src/mobile/android/mod.rsRepository: agentic-review-benchmarks/tauri-combined-coderabbit
Length of output: 585
🏁 Script executed:
#!/bin/bash
# Get the full implementation of generate_tauri_properties to see if dev parameter is used
sed -n '625,680p' crates/tauri-cli/src/mobile/android/mod.rsRepository: agentic-review-benchmarks/tauri-combined-coderabbit
Length of output: 2499
Auto-increment versionCode executes during dev runs when autoIncrementVersionCode is enabled.
The dev parameter is passed to generate_tauri_properties() but is not checked in the auto-increment logic (lines 635-645 in mod.rs). When autoIncrementVersionCode is enabled, versionCode increments on every tauri android dev invocation, potentially causing unintended version inflation.
The dev parameter is only used later in a different code branch for validation. To prevent auto-increment during development, guard the auto-increment condition:
Suggested fix in crates/tauri-cli/src/mobile/android/mod.rs
- if tauri_config.bundle.android.auto_increment_version_code {
+ if tauri_config.bundle.android.auto_increment_version_code && !dev {🤖 Prompt for AI Agents
In `@crates/tauri-cli/src/mobile/android/dev.rs` around lines 274 - 275, The
auto-increment logic in generate_tauri_properties is ignoring the dev flag and
increments versionCode during dev runs; update the condition that checks
autoIncrementVersionCode/versionCode (the block around the auto-increment logic
in generate_tauri_properties) to also require that dev is false (i.e., only
auto-increment when !dev), so calls like generate_tauri_properties(..., true)
from the dev flow will not bump versionCode during development.
| 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}")); | ||
| } else if let Some(version_code) = tauri_config.bundle.android.version_code.as_ref() { | ||
| app_tauri_properties.push(format!("tauri.android.versionCode={version_code}")); |
There was a problem hiding this comment.
Honor dev and enforce versionCode bounds in auto-increment path.
dev isn’t used in the auto-increment branch, so dev runs still bump the version code. Also, auto-increment and explicit version_code can exceed the 2,100,000,000 limit without any validation.
🛠️ Proposed fix
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);
+ let new_version_code = if dev {
+ last_version_code.unwrap_or(1)
+ } else {
+ last_version_code.map(|v| v.saturating_add(1)).unwrap_or(1)
+ };
+ if new_version_code == 0 || new_version_code > 2100000000 {
+ crate::error::bail!(
+ "Invalid version code {}. Version code must be between 1 and 2100000000.",
+ new_version_code
+ );
+ }
app_tauri_properties.push(format!("tauri.android.versionCode={new_version_code}"));
} else if let Some(version_code) = tauri_config.bundle.android.version_code.as_ref() {
+ if *version_code == 0 || *version_code > 2100000000 {
+ crate::error::bail!(
+ "Invalid version code {}. Version code must be between 1 and 2100000000.",
+ version_code
+ );
+ }
app_tauri_properties.push(format!("tauri.android.versionCode={version_code}"));
} else if let Ok(version) = Version::parse(version) {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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}")); | |
| } else if let Some(version_code) = tauri_config.bundle.android.version_code.as_ref() { | |
| app_tauri_properties.push(format!("tauri.android.versionCode={version_code}")); | |
| 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 = if dev { | |
| last_version_code.unwrap_or(1) | |
| } else { | |
| last_version_code.map(|v| v.saturating_add(1)).unwrap_or(1) | |
| }; | |
| if new_version_code == 0 || new_version_code > 2100000000 { | |
| crate::error::bail!( | |
| "Invalid version code {}. Version code must be between 1 and 2100000000.", | |
| new_version_code | |
| ); | |
| } | |
| app_tauri_properties.push(format!("tauri.android.versionCode={new_version_code}")); | |
| } else if let Some(version_code) = tauri_config.bundle.android.version_code.as_ref() { | |
| if *version_code == 0 || *version_code > 2100000000 { | |
| crate::error::bail!( | |
| "Invalid version code {}. Version code must be between 1 and 2100000000.", | |
| version_code | |
| ); | |
| } | |
| app_tauri_properties.push(format!("tauri.android.versionCode={version_code}")); |
🤖 Prompt for AI Agents
In `@crates/tauri-cli/src/mobile/android/mod.rs` around lines 635 - 648, The
auto-increment branch should honor the dev flag and clamp version codes to
Android's max; change the logic around
tauri_config.bundle.android.auto_increment_version_code to first check
tauri_config.build.dev and, if dev is true, use last_version_code.unwrap_or(1)
without incrementing, otherwise compute new_version_code =
last_version_code.map(|v| v.saturating_add(1)).unwrap_or(1) and then clamp it to
a constant MAX_VERSION_CODE = 2_100_000_000 (e.g. new_version_code =
std::cmp::min(new_version_code, MAX_VERSION_CODE)); also validate/clamp the
explicit tauri_config.bundle.android.version_code path so the pushed value
(app_tauri_properties.push(...)) is never greater than MAX_VERSION_CODE and
always uses the clamped numeric value rather than the raw input.
| "autoIncrementVersionCode": { | ||
| "description": "Whether to automatically increment the `versionCode` on each build.\n\n - If `true`, the generator will try to read the last `versionCode` from\n `tauri.properties` and increment it by 1 for every build.\n - If `false` or not set, it falls back to `version_code` or semver-derived logic.\n\n Note that to use this feature, you should remove `/tauri.properties` from `src-tauri/gen/android/app/.gitignore` so the current versionCode is committed to the repository.", | ||
| "default": false, |
There was a problem hiding this comment.
Use versionCode in the description.
The schema is user-facing and camelCase elsewhere; referencing snake_case can confuse config authors.
✏️ Proposed doc tweak
- - If `false` or not set, it falls back to `version_code` or semver-derived logic.
+ - If `false` or not set, it falls back to `versionCode` or semver-derived logic.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "autoIncrementVersionCode": { | |
| "description": "Whether to automatically increment the `versionCode` on each build.\n\n - If `true`, the generator will try to read the last `versionCode` from\n `tauri.properties` and increment it by 1 for every build.\n - If `false` or not set, it falls back to `version_code` or semver-derived logic.\n\n Note that to use this feature, you should remove `/tauri.properties` from `src-tauri/gen/android/app/.gitignore` so the current versionCode is committed to the repository.", | |
| "default": false, | |
| "autoIncrementVersionCode": { | |
| "description": "Whether to automatically increment the `versionCode` on each build.\n\n - If `true`, the generator will try to read the last `versionCode` from\n `tauri.properties` and increment it by 1 for every build.\n - If `false` or not set, it falls back to `versionCode` or semver-derived logic.\n\n Note that to use this feature, you should remove `/tauri.properties` from `src-tauri/gen/android/app/.gitignore` so the current versionCode is committed to the repository.", | |
| "default": false, |
🤖 Prompt for AI Agents
In `@crates/tauri-schema-generator/schemas/config.schema.json` around lines 3832 -
3834, Update the user-facing description for the autoIncrementVersionCode schema
entry to use the camelCase field name "versionCode" instead of "version_code";
locate the "autoIncrementVersionCode" property in the JSON schema and edit its
"description" text to replace any occurrences of "version_code" with
"versionCode" while keeping the rest of the explanatory text and default
unchanged.
Benchmark PR from agentic-review-benchmarks#1
Summary by CodeRabbit
bundle.android.autoIncrementVersionCodeenables automatic incrementation of the Android version code on each build, simplifying version management for Android applications.