Skip to content

Commit

Permalink
feat(cli): handle Android package identifier change (#6314)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Feb 19, 2023
1 parent dffd8eb commit 79eb054
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changes/error-on-identifier-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Print an error if the Android project was generated with an older bundle identifier or package name.
26 changes: 16 additions & 10 deletions tooling/cli/src/mobile/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use clap::{Parser, Subcommand};
use std::{
env::set_var,
process::exit,
thread::{sleep, spawn},
time::Duration,
};
Expand Down Expand Up @@ -124,19 +125,24 @@ pub fn get_config(
format!("{}.{}", app.reverse_domain(), app.name_snake()),
);
set_var("WRY_ANDROID_LIBRARY", app.lib_name());
set_var("TAURI_ANDROID_PROJECT_PATH", config.project_dir());

let src_main_dir = config.project_dir().join("app/src/main").join(format!(
"java/{}/{}",
app.reverse_domain().replace('.', "/"),
app.name_snake()
));
if config.project_dir().exists() && !src_main_dir.exists() {
log::error!(
"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.",
src_main_dir.display()
);
exit(1);
}
set_var(
"WRY_ANDROID_KOTLIN_FILES_OUT_DIR",
config
.project_dir()
.join("app/src/main")
.join(format!(
"java/{}/{}",
app.reverse_domain().replace('.', "/"),
app.name_snake()
))
.join("generated"),
src_main_dir.join("generated"),
);
set_var("TAURI_ANDROID_PROJECT_PATH", config.project_dir());

(app, config, metadata)
}
Expand Down

0 comments on commit 79eb054

Please sign in to comment.