title: Android Proguard Javascript Interface Fail
body: <p>I use in my project a piece of code as described here</p>
  
  <p><a href="http://lexandera.com/2009/01/extracting-html-from-a-webview/" rel="nofollow noreferrer">http://lexandera.com/2009/01/extracting-html-from-a-webview/</a></p>
  
  <p>I create the .apk file, install it on my device and it correctly works. If I try to use the obfuscation with proguard the project fails, the method showHTML(String html) of MyJavaScriptInterface is not reached.</p>
  
  <p>My proguard configuration regarding that</p>
  
  <pre><code>-keep public class com.mypackage.MyClass.MyJavaScriptInterface
  -keep public class * implements com.mypackage.MyClass.MyJavaScriptInterface
  -keepclassmembers class * implements com.mypackage.MyClass.MyJavaScriptInterface { 
      &lt;methods&gt;; 
  }
  </code></pre>
  
  <p>according to this this answer <a href="https://stackoverflow.com/questions/5356560/android-proguard-javascript-interface-problem">Android proguard Javascript Interface problem</a>.</p>
  
  <p><strong>SOLVED.</strong></p>
  
  <p>As Eric suggested, I changed the Proguard configuration file like this:</p>
  
  <pre><code>-keep public class com.mypackage.MyClass$MyJavaScriptInterface
  -keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface
  -keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { 
      &lt;methods&gt;; 
  }
  </code></pre>
  
  <p>Now my project works perfectly.</p>
  
  <p>For API 17+ you also need to preserve the @JavascriptInterface annotations:</p>
  
  <pre><code>-keepattributes JavascriptInterface
  </code></pre>
  
  <p><a href="http://developer.android.com/reference/android/webkit/JavascriptInterface.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/webkit/JavascriptInterface.html</a></p>