Skip to content

Commit

Permalink
feat: generate proguard rule file for android (#927)
Browse files Browse the repository at this point in the history
* feat: generate proguard rule file for android

* remove `AppCompatActivity` from `proguard-wry.pro`
  • Loading branch information
amrbashir authored Apr 17, 2023
1 parent d560981 commit ced4c0b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/proguard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": "patch"
---

On Android, generate a `proguard-wry.pro` file that could be used to keep the necessary symbols for wry when using minification.
13 changes: 12 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ fn main() {
&std::env::var(&class_init_env).unwrap_or_default(),
);

let mut out = String::from("/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */\n\n");
let auto_generated_comment = match file
.path()
.extension()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
{
"pro" => "# THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!!\n\n",
"kt" => "/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */\n\n",
_ => "String::new()",
};
let mut out = String::from(auto_generated_comment);
out.push_str(&content);

fs::write(kotlin_out_dir.join(file.file_name()), out).expect("Failed to write kotlin file");
Expand Down
36 changes: 36 additions & 0 deletions src/webview/android/kotlin/proguard-wry.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2020-2023 Tauri Programme within The Commons Conservancy
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

-keep class {{package}}.* {
native <methods>;
}

-keep class {{package}}.WryActivity {
{{package}}.RustWebView m_webview;

public <init>(...);

void setM_webview({{package}}.RustWebView);
{{package}}.RustWebView getM_webview();

java.lang.Class getAppClass(...);
java.lang.String getVersion();
}

-keep class {{package}}.Ipc {
public <init>(...);

@android.webkit.JavascriptInterface public <methods>;
}

-keep class {{package}}.RustWebView {
public <init>(...);

void loadUrlMainThread(...);
void setAutoPlay(...);
}

-keep class {{package}}.RustWebChromeClient,{{package}}.RustWebViewClient {
public <init>(...);
}

0 comments on commit ced4c0b

Please sign in to comment.