Skip to content

Commit

Permalink
fix(cli & core): use unescaped package id in proguard file (#11314)
Browse files Browse the repository at this point in the history
* 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 <lucas@tauri.app>
  • Loading branch information
amrbashir and lucasfernog authored Oct 11, 2024
1 parent 4731f0c commit d609bef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changes/android-proguard.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions crates/tauri-cli/src/mobile/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
20 changes: 9 additions & 11 deletions crates/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d609bef

Please sign in to comment.