Skip to content

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

Open
tomerqodo wants to merge 6 commits into
qodo_action_req_1_base_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1from
qodo_action_req_1_head_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1
Open

tomerqodo wants to merge 6 commits into
qodo_action_req_1_base_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1from
qodo_action_req_1_head_featandroid_add_auto_increment_version_code_option_for_android_builds__pr1

Conversation

@tomerqodo

Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#1

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (2) 📎 Requirement gaps (0)

Grey Divider


Action required

1. tauri_config double unwrap() 📘 Rule violation ⛯ Reliability
Description
• 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.
Code

crates/tauri-cli/src/mobile/android/build.rs[R181-185]

+  generate_tauri_properties(
+    &config,
+    tauri_config.lock().unwrap().as_ref().unwrap(),
+    false,
+  )?;
Evidence
PR Compliance ID 21 forbids using unwrap()/panics for fallible operations where Result-based
error handling is appropriate. The added Android build/dev paths include unwrap() on a lock
acquisition and optional value access, which can panic instead of returning a structured error.

AGENTS.md
crates/tauri-cli/src/mobile/android/build.rs[181-185]
crates/tauri-cli/src/mobile/android/dev.rs[274-274]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


2. generate_tauri_properties undocumented 📘 Rule violation ✧ Quality
Description
• 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.
Code

crates/tauri-cli/src/mobile/android/mod.rs[R625-629]

+pub fn generate_tauri_properties(
+  config: &AndroidConfig,
+  tauri_config: &TauriConfig,
+  dev: bool,
+) -> Result<()> {
Evidence
PR Compliance ID 13 requires documentation comments for public APIs. The new public function is
declared without any preceding /// docs.

AGENTS.md
crates/tauri-cli/src/mobile/android/mod.rs[625-629]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


3. Auto-increment exceeds max 🐞 Bug ✓ Correctness
Description
• 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.
Code

crates/tauri-cli/src/mobile/android/mod.rs[R635-646]

+    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}"));
Evidence
The schema explicitly constrains Android versionCode to <= 2100000000, but the auto-increment
code reads an arbitrary u32 from tauri.properties and increments it without enforcing this
limit. The Android template then consumes this property as an Int, so an out-of-range value will
surface during build/publish.

crates/tauri-cli/src/mobile/android/mod.rs[633-646]
crates/tauri-cli/config.schema.json[3822-3835]
crates/tauri-cli/templates/mobile/android/app/build.gradle.kts[11-28]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### 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


View more (1)
4. tauri.properties generation regression 🐞 Bug ⛯ Reliability
Description
• 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.
Code

crates/tauri-build/src/mobile.rs[R10-13]

+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");
Evidence
The Android template reads tauri.properties for version metadata with defaults if missing. After
this PR, tauri-build’s generate_gradle_files no longer writes tauri.properties, while generation
is now only performed inside tauri-cli Android build/dev commands. Therefore, direct Gradle builds
can use defaults or stale values unless the CLI is run to generate/update the file.

crates/tauri-build/src/mobile.rs[10-62]
crates/tauri-cli/templates/mobile/android/app/build.gradle.kts[11-28]
crates/tauri-cli/templates/mobile/android/app/.gitignore[4-6]
crates/tauri-cli/src/mobile/android/build.rs[178-188]
crates/tauri-cli/src/mobile/android/dev.rs[268-276]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### 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



ⓘ The new review experience is currently in Beta. Learn more

Qodo Logo

Comment on lines +181 to +185
generate_tauri_properties(
&config,
tauri_config.lock().unwrap().as_ref().unwrap(),
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.

Action required

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

Comment on lines +625 to +629
pub fn generate_tauri_properties(
config: &AndroidConfig,
tauri_config: &TauriConfig,
dev: bool,
) -> Result<()> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

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

Comment on lines +10 to 13
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");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

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

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