Android ProGuard加密webview的JavascriptInterface注解annotation的问题

Posted 奥特曼超人Dujinyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android ProGuard加密webview的JavascriptInterface注解annotation的问题相关的知识,希望对你有一定的参考价值。

或作或辍,一曝十寒,则虽读书百年,吾未见其可也。——(明)吴梦祥


原因:
使用 @android.webkit.javascriptInterfaceJavascriptInterface 原因导致加密后找不到这个类的方法,主要是加密后原有的类下方法是普通的annotation,无法导入js交互中。

// Compiled from JavascriptInterface.java (version 1.5 : 49.0, no super bit)
@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
@java.lang.annotation.Target(value=java.lang.annotation.ElementType.METHOD)
public abstract @interface android.webkit.JavascriptInterface extends java.lang.annotation.Annotation 


加密过程的警告可以忽略:

Note: the configuration refers to the unknown class 'com.xx.WebViewActivity.JavascriptInterface'
      Maybe you meant the fully qualified name 'android.webkit.JavascriptInterface'?
Note: the configuration refers to the unknown class com.xx.WebViewActivity.JavascriptInterface'
      Maybe you meant the fully qualified name 'android.webkit.JavascriptInterface'?
Note: the configuration refers to the unknown class 'com.xx.WebViewActivity.JavascriptInterface'
      Maybe you meant the fully qualified name 'android.webkit.JavascriptInterface'?
Note: the configuration refers to the unknown class 'JavascriptInterface'
      Maybe you meant the fully qualified name 'android.webkit.JavascriptInterface'?
Note: there were 4 references to unknown classes.
      You should check your configuration for typos.
Note: there were 1 unresolved dynamic references to classes or interfaces.
      You should check if you need to specify additional program jars.
Note: there were 1 accesses to class members by means of introspection.
      You should consider explicitly keeping the mentioned class members
      (using '-keep' or '-keepclassmembers').

最后解决:


-keepclassmembers class com.xx.WebViewActivity$JavascriptInterface 
    public <fields>;
    public <methods>;


# keep annotated by JavascriptInterface
-keep @com.xx..WebViewActivity.JavascriptInterface class * 
    <fields>;
    <methods>;


-keep class * 
    @com.xx.WebViewActivity.JavascriptInterface
    <fields>;


-keepclassmembers class * 
    @com.xx.WebViewActivity.JavascriptInterface
    <methods>;


-keep class android.support.** 
    <fields>;
    <methods>;


-keep class com.xx.WebViewActivity.** 
    <fields>;
    <methods>;


-keepclassmembers classcom.xx.WebViewActivity$JavascriptInterface 
    <methods>;


推荐文章:


|| 版权声明:本文为博主杜锦阳原创文章,转载请注明出处。

以上是关于Android ProGuard加密webview的JavascriptInterface注解annotation的问题的主要内容,如果未能解决你的问题,请参考以下文章

Android Proguard Javascript接口失败

防止 Proguard 删除特定的可绘制对象

带有 proguard 的 Android ant build.xml 未在发行版中构建

如何为javascript接口配置proguard?

Android apk如何加固防止被破解(防止逆向编译)

Android apk如何加固防止被破解(防止逆向编译)