Skip to content

feat(android): add auto_increment_version_code option for Android builds #1

Open
tomerqodo wants to merge 6 commits into
coderabbit_full_base_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1from
coderabbit_full_head_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1
Open

feat(android): add auto_increment_version_code option for Android builds #1
tomerqodo wants to merge 6 commits into
coderabbit_full_base_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1from
coderabbit_full_head_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1

Conversation

@tomerqodo

@tomerqodo tomerqodo commented Jan 30, 2026

Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#1

Summary by CodeRabbit

  • New Features
    • Added automatic Android version code incrementation. A new configuration option bundle.android.autoIncrementVersionCode enables automatic incrementation of the Android version code on each build, simplifying version management for Android applications.

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request adds automatic Android version code incrementation functionality to Tauri. A new configuration option autoIncrementVersionCode is introduced to bundle Android settings, along with a new generate_tauri_properties function that manages Android versionName and versionCode generation. Build and dev flows are updated to call this function during Android development.

Changes

Cohort / File(s) Summary
Configuration Schema Definitions
crates/tauri-cli/config.schema.json, crates/tauri-schema-generator/schemas/config.schema.json, crates/tauri-utils/src/config.rs
Added autoIncrementVersionCode boolean field to Android configuration in schemas and AndroidConfig struct, with serde alias and default value of false.
Android Properties Generation
crates/tauri-cli/src/mobile/android/mod.rs
New public function generate_tauri_properties that builds and writes tauri.properties file, computing versionName and versionCode based on config and semantic versioning; supports automatic versionCode incrementation with bounds validation (non-zero, upper limit 2100000000) and dev-mode clamping.
Build Integration
crates/tauri-cli/src/mobile/android/build.rs, crates/tauri-cli/src/mobile/android/dev.rs
Integrated calls to generate_tauri_properties in Android build and dev flows prior to setup/installation, passing config and resolved tauri config.
Build System Refactoring
crates/tauri-build/src/lib.rs, crates/tauri-build/src/mobile.rs
Simplified generate_gradle_files function signature by removing Config parameter; removed tauri.properties generation from Gradle generation logic and eliminated version-based property handling.
Changelog
.changes/auto-increment-android-version-code.md
Documented new feature as minor additions across tauri-cli, @tauri-apps/cli, tauri-build, and tauri-utils packages.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Hops of joy, the versions now grow!
With each build, the code takes flight,
Auto-increment sets the glow,
Android's versionCode shines bright,
Bounded safe, from dev to go! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding an auto_increment_version_code configuration option for Android builds, which is a new feature affecting the Android build process.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch coderabbit_full_head_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +274 to +275
generate_tauri_properties(config, tauri_config.lock().unwrap().as_ref().unwrap(), true)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 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.rs

Repository: 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.rs

Repository: 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.rs

Repository: 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.rs

Repository: 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.

Comment on lines +635 to +648
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}"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

Comment on lines +3832 to +3834
"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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
"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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants