0

我在我的应用程序中使用 Javascript 接口。

当我在我的设备(Galaxy 3)上运行调试时,它运行完美,没有任何问题,但是当我制作发布 apk 文件时,JavaScript 可能没有运行。

这是JavaScriptInterface类:

public class StreamingMediaPlayer{

    public class JavaScriptInterface {
        Context mContext;

        JavaScriptInterface(Context c) {
             mContext = c;
        }

        @JavascriptInterface
        public void FinishExtract(String url) {

        }
   }
}

现在我认为这是因为proguard文件:

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-dontwarn org.apache.commons.codec.binary.**
-dontwarn com.commonsware.cwac.sacklist.**
-dontwarn com.commonsware.cwac.tlv.**
-dontwarn com.nineoldandroids.**
-dontwarn com.apps.model.**

-keep class com.millennialmedia.android.** {*;}
-keep public class cmn.Proguard$KeepMembers 
-keep public class * implements cmn.Proguard$KeepMembers
-keepclassmembers class * implements cmn.Proguard$KeepMembers { 
   <methods>; 
}
-keepattributes *Annotation*
-dontwarn android.webkit.JavascriptInterface

-keep class com.apps.model.** { *; } 
-keepattributes *Annotation*

我需要在proguard文件中添加一些东西吗?问题可能是其他问题吗?

4

1 回答 1

1

问题是 proguard 混淆了 FinishExtract 方法。然后javascript找不到它,因为它假定名称仍然是“FinishExtract”

要修复它,您可以将代码更改为:

public class JavaScriptInterface  implements cmn.Proguard.KeepMembers {

您的 proguard 配置指定实现 KeepMembers 的类应保持未混淆。

于 2013-11-20T21:15:40.467 回答