Android上的JavascriptInterface在发布模式下无法使用APK [英] JavascriptInterface on Android dont work with APK in release mode

查看:110
本文介绍了Android上的JavascriptInterface在发布模式下无法使用APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,即两天前我正在寻找解决方案。在搜索令人沮丧之后,我将在这里发帖:



我创建了一个具有webview的示例应用程序,这个webview打开了一个url,其中包含一个调用android函数的链接。我按照它:
了解详情。


I have a problem that im searching for a solution since two days ago. After frustrating searchs, i will post here:

I have created a sample app that have a webview and this webview open a url that have a link to call a android function. I follow it: http://developer.android.com/guide/webapps/webview.html#BindingJavaScript

Im using last AndroidStudio version and im using a galaxy s4 mini for test.

When i debug it, everything works correct and a toast is showed.

The problem is when i generate a RELEASE application with command: ~/Server/gradle-1.8/bin/gradle assembleRelease

The application open, but when i touch the link that call my native function, it dont work and nothing happen. But with debug mode, it works.

Can anyone help me?

An image to understand better:

解决方案

If Gradle is configured to use ProGuard, the @JavascriptInterface annotations need to be explicitly preserved.

-keep public class com.mypackage.MyClass$MyJavaScriptInterface
-keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface
-keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { 
    <methods>; 
}
-keepattributes JavascriptInterface

See here for details.

这篇关于Android上的JavascriptInterface在发布模式下无法使用APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆