From d609bef9fd7cd6eeb2bd701558100bd9cfb6e6f6 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Fri, 11 Oct 2024 22:17:29 +0300 Subject: [PATCH] fix(cli & core): use unescaped package id in proguard file (#11314) * fix(cli & core): use unescaped package id in proguard file closes #11310 * add monkey patch for wry proguard * fix tests * typo * remove wry fix --------- Co-authored-by: Lucas Nogueira --- .changes/android-proguard.md | 7 +++++++ crates/tauri-cli/src/mobile/android/mod.rs | 1 + crates/tauri/build.rs | 20 +++++++++----------- 3 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 .changes/android-proguard.md diff --git a/.changes/android-proguard.md b/.changes/android-proguard.md new file mode 100644 index 000000000000..d9914873e766 --- /dev/null +++ b/.changes/android-proguard.md @@ -0,0 +1,7 @@ +--- +"tauri": "patch:bug" +"tauri-cli": "patch:bug" +"@tauri-apps/cli": "patch:bug" +--- + +Fix android invalid proguard file when using an `identifier` that contains a component that is a reserved kotlin keyword, like `in`, `class`, etc diff --git a/crates/tauri-cli/src/mobile/android/mod.rs b/crates/tauri-cli/src/mobile/android/mod.rs index 1866c8ab9700..7521e87a9d4e 100644 --- a/crates/tauri-cli/src/mobile/android/mod.rs +++ b/crates/tauri-cli/src/mobile/android/mod.rs @@ -139,6 +139,7 @@ pub fn get_config( "WRY_ANDROID_PACKAGE", app.android_identifier_escape_kotlin_keyword(), ); + set_var("TAURI_ANDROID_PACKAGE_UNESCAPED", app.identifier()); set_var("WRY_ANDROID_LIBRARY", app.lib_name()); set_var("TAURI_ANDROID_PROJECT_PATH", config.project_dir()); diff --git a/crates/tauri/build.rs b/crates/tauri/build.rs index 6d51bdecf0ca..047f2843956c 100644 --- a/crates/tauri/build.rs +++ b/crates/tauri/build.rs @@ -260,13 +260,13 @@ fn main() { } if target_os == "android" { - if let Ok(kotlin_out_dir) = std::env::var("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") { - fn env_var(var: &str) -> String { - std::env::var(var).unwrap_or_else(|_| { - panic!("`{var}` is not set, which is needed to generate the kotlin files for android.") - }) - } + fn env_var(var: &str) -> String { + std::env::var(var).unwrap_or_else(|_| { + panic!("`{var}` is not set, which is needed to generate the kotlin files for android.") + }) + } + if let Ok(kotlin_out_dir) = std::env::var("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") { let package = env_var("WRY_ANDROID_PACKAGE"); let library = env_var("WRY_ANDROID_LIBRARY"); @@ -299,11 +299,9 @@ fn main() { } if let Some(project_dir) = env::var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) { - let tauri_proguard = include_str!("./mobile/proguard-tauri.pro").replace( - "$PACKAGE", - &env::var("WRY_ANDROID_PACKAGE") - .expect("missing `WRY_ANDROID_PACKAGE` environment variable"), - ); + let package_unescaped = env_var("TAURI_ANDROID_PACKAGE_UNESCAPED"); + let tauri_proguard = + include_str!("./mobile/proguard-tauri.pro").replace("$PACKAGE", &package_unescaped); std::fs::write( project_dir.join("app").join("proguard-tauri.pro"), tauri_proguard,