Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android proguard Javascript Interface problem

My project after obfuscation with proguard fail with javascriptinterface

Here is the link with some suggestions for proguard configuration but it dosn't work in my case

http://groups.google.com/group/android-developers/browse_thread/thread/f889e846fbf7ec3f?pli=1

So the calls from Javascript loose binding to the associated Java methods

My proguard configuration regarding that

-keep public class com.trans_code.android.JavascriptCallback 
-keep public class * implements com.trans_code.android.JavascriptCallback 
-keepclassmembers class * implements com.trans_code.android.JavascriptCallback { 
    <methods>; 
} 
-keepclassmembers class * implements JavascriptCallback { 
    void on*(***);
} 
-keep public class com.trans_code.** {
  public protected *;
}

-keepclasseswithmembernames class com.MyActivity$JavascriptInterface

-keepclasseswithmembernames class com.MyActivity$JavascriptInterface {
    public protected *;
}

if anyone knows how to configure proguard to have it filter out related methods and classes that will help me a lot

like image 778
Artavazd Avatar asked Mar 18 '11 18:03

Artavazd


1 Answers

The class names from that original thread are specific to that users Java classes, and not generic to to all javascript interfaces. The javascript interface you implement is just a simple base class.

You need to change them to match the name of your interface class.

For example the correct configuration, based on the example from the original thread, for the sample code WebViewDemo would be:

-keep public class com.google.android.webviewdemo.WebViewDemo.DemoJavaScriptInterface
-keep public class * implements com.google.android.webviewdemo.WebViewDemo.DemoJavaScriptInterface 
-keepclassmembers class * implements com.google.android.webviewdemo.WebViewDemo.DemoJavaScriptInterface { 
    <methods>; 
} 

Due to the way the bindings work all that really needs to be done is to keep the inner methods that will be called from javascript from having the names obfuscated, but keeping the class name from obfuscation doesn't hurt.

like image 176
cistearns Avatar answered Oct 11 '22 06:10

cistearns