Skip to content

Commit 79eb054

Browse files
authored
feat(cli): handle Android package identifier change (#6314)
1 parent dffd8eb commit 79eb054

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Print an error if the Android project was generated with an older bundle identifier or package name.

tooling/cli/src/mobile/android.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use clap::{Parser, Subcommand};
66
use std::{
77
env::set_var,
8+
process::exit,
89
thread::{sleep, spawn},
910
time::Duration,
1011
};
@@ -124,19 +125,24 @@ pub fn get_config(
124125
format!("{}.{}", app.reverse_domain(), app.name_snake()),
125126
);
126127
set_var("WRY_ANDROID_LIBRARY", app.lib_name());
128+
set_var("TAURI_ANDROID_PROJECT_PATH", config.project_dir());
129+
130+
let src_main_dir = config.project_dir().join("app/src/main").join(format!(
131+
"java/{}/{}",
132+
app.reverse_domain().replace('.', "/"),
133+
app.name_snake()
134+
));
135+
if config.project_dir().exists() && !src_main_dir.exists() {
136+
log::error!(
137+
"Project directory {} does not exist. Did you update the package name in `Cargo.toml` or the bundle identifier in `tauri.conf.json > tauri > bundle > identifier`? Save your changes, delete the `gen/android` folder and run `tauri android init` to recreate the Android project.",
138+
src_main_dir.display()
139+
);
140+
exit(1);
141+
}
127142
set_var(
128143
"WRY_ANDROID_KOTLIN_FILES_OUT_DIR",
129-
config
130-
.project_dir()
131-
.join("app/src/main")
132-
.join(format!(
133-
"java/{}/{}",
134-
app.reverse_domain().replace('.', "/"),
135-
app.name_snake()
136-
))
137-
.join("generated"),
144+
src_main_dir.join("generated"),
138145
);
139-
set_var("TAURI_ANDROID_PROJECT_PATH", config.project_dir());
140146

141147
(app, config, metadata)
142148
}

0 commit comments

Comments
 (0)