Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate proguard rule file for android #927

Merged
merged 3 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>(...);
}