Web View 具有由 Web 调用并用 @JavascriptInterface
注释的桥接器和方法。
该应用程序在没有 Proguard 的调试版本和发布版本中运行良好。但是当 Proguard 打开时,应用程序不会收到来自网络的回调。
Web 调用的 Javascript 方法也使用 @Keep
注释和 webview 桥接类进行注释。
但由于某种原因,Android 应用程序中的 webview 桥接方法仍然没有被调用。
编辑: 这是通过 web 运行的方法的代码。
/**
* This method gets called from the WebApp and logs the user
* in the app using native Facebook Sign In implementation
* in {@link MainActivity#initFacebookSignIn(String callback)}
*/
@JavascriptInterface
public void initFacebookSignIn(String callback) {
activity.initFacebookSignIn(callback);
}
有什么想法吗?
最佳答案
将这些规则添加到您的混淆器中:
-dontwarn javax.annotation.**
-keepattributes Signature
-keepattributes Exceptions
-keepattributes SetJavaScriptEnabled
-keepattributes JavascriptInterface
-keepattributes InlinedApi
-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
关于javascript - 发布版本中未调用 Webview Javascript 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57782250/