In my app's webview some contents are derived from a class object. From WebView's document here:
Caution: If you've set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available to your JavaScript (the method must also be public). If you do not provide the annotation, the method is not accessible by your web page when running on Android 4.2 or higher.
What if I have a class and I would like to make all methods of this class accessible by my WebView? Do I need to add @JavascriptInterface
to every single method? Is there another way to achieve this efficiently?
On the other hand, I am not familiar with ProGuard, I've read some posts here as well as some other stuffs (e.g. usage page for proguard) about ProGuard. I am confused about it and its usage. Do I have to configure ProGuard on this issue?
Currently I seem to be able to access methods with @JavascriptInterface
without configuring them in ProGuard. However I saw many post regarding ProGuard and JavascriptInterface (like post 1 and post 2) are using the keep
options with those classes, if I didn't get it wrong is this because those methods/classes are only used by the javascript in WebView, hence marking them "never used" and will be removed by ProGuard?
Thanks!