0
我在我的應用程序中使用Javascript接口。Android的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
文件?問題可以是別的嗎?
將StreamingMediaPlayer類添加到proguard文件不是一個更好的主意嗎?也可以根據proguard文件中的註釋說明取消註釋webview的配置 – GreyBeardedGeek
是將StreamingMediaPlayer.JavaScriptInterface添加到proguard配置中也可以修復它。我更喜歡這個接口的解決方案,因爲您只需要添加一次,並且可以在很多地方使用它(例如,用於多個JavaScript接口類),而無需保持類名與proguard配置同步。 – uwe