【问题标题】:NoSuchMethodError for VideoView.setOnPreparedListener()VideoView.setOnPreparedListener() 的 NoSuchMethodError
【发布时间】:2014-11-13 22:05:28
【问题描述】:

我在使用 Proguard 和我的应用程序的自定义 VideoView 时遇到问题。似乎混淆我的代码会导致我的 VideoView 出现问题。每当我尝试为视频设置 OnPreparedListener 时,我的应用程序就会崩溃。见:

11-13 15:54:45.881  19428-19428/com.<REDACTED> E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.<REDACTED>, PID: 19428
java.lang.NoSuchMethodError: No virtual method setOnPreparedListener(Landroid/media/MediaPlayer$e;)V in class Landroid/widget/VideoView; or its super classes (declaration of 'android.widget.VideoView' appears in /system/framework/framework.jar:classes2.dex)
        at com.<REDACTED>.ui.module.MHVideoPlayerModule.initializeVideoPlayer(MHVideoPlayerModule.java:174)
        at com.<REDACTED>.ui.module.MHVideoPlayerModule.initializeViewData(MHVideoPlayerModule.java:154)
        at com.<REDACTED>.ui.activity.MHVideoDetailActivity.a(MHVideoDetailActivity.java:198)
        at com.<REDACTED>.ui.activity.MHVideoDetailActivity.b(MHVideoDetailActivity.java:171)
        at com.<REDACTED>.ui.activity.MHVideoDetailActivity.a_(MHVideoDetailActivity.java:255)
        at com.<REDACTED>.service.f.al.b(MHVideoUrlTaskManager.java:131)
        at com.<REDACTED>.service.a.e.onPostExecute(MHAsyncServiceTask.java:194)
        at android.os.AsyncTask.finish(AsyncTask.java:632)
        at android.os.AsyncTask.access$600(AsyncTask.java:177)
        ...

我尝试将以下几行添加到 Proguard 文件中,但它们没有帮助。

-keep class com.<REDACTED>.ui.module.MHVideoPlayerModule { *; }
-keep class android.widget.VideoView { *; }

编辑:这是proguard-project.txt 文件:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class com.<REDACTED>.common.JavaScriptInterface {
   public *;
}

# Google Play Services start
# https://developer.android.com/google/play-services/setup.html
-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}
# Google Play Services end

-dontwarn javax.jdo.**
-dontwarn javax.naming.**
-dontwarn com.google.api.client.googleapis.extensions.android.gms.**
-dontwarn com.google.android.gms.**
-dontwarn com.squareup.okhttp.**

-keep public class android.net.http.SslError
-keep public class android.webkit.WebViewClient
-keep public class android.widget.VideoView

-dontwarn android.webkit.WebView
-dontwarn android.net.http.SslError
-dontwarn android.webkit.WebViewClient
-dontwarn android.media.MediaPlayer
-dontwarn android.widget.VideoView

-dontwarn org.bouncycastle.**
-dontwarn org.apache.commons.codec.binary.Base64

-keepattributes SourceFile,LineNumberTable
-printusage build/outputs/proguard/unused.txt
-printconfiguration build/outputs/proguard/configuration.txt

-libraryjars libs

-keep class com.crashlytics.** { *; }
-keep class io.fabric.** { *; }
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.facebook.** { *; }

# New Relic start
# https://docs.newrelic.com/docs/mobile-monitoring/mobile-monitoring-installation/android/installing-android-apps-gradle-android-studio#proguard
-keep class com.newrelic.** { *; }
-dontwarn com.newrelic.**
-keepattributes Exceptions, Signature, InnerClasses
# New Relic end

-dontshrink

【问题讨论】:

  • Proguard 代码重新创建问题会很好。
  • 在原帖中添加了progaurd-project.txt文件。

标签: android proguard


【解决方案1】:

看来您还提供了自定义 android.media.MediaPlayer 和/或 android.media.MediaPlayer.OnPreparedListener 实现:

java.lang.NoSuchMethodError: 类 Landroid/widget/VideoView 中没有虚拟方法 setOnPreparedListener(Landroid/media/MediaPlayer$e;)V;或其超类('android.widget.VideoView' 的声明出现在 /system/framework/framework.jar:classes2.dex 中)

setOnPreparedListener -- 你正在调用的方法

(L -- 对象的 smali 前缀

android/media/MediaPlayer$e -- 您尝试传递给方法的实际类型名称。 这就是问题所在。 内部类类型OnPreparedListener 被混淆了。应该是android/media/MediaPlayer$OnPreparedListener

android/widget/VideoView 试图承载此方法签名的类。


您是否有使用原始包名称的自定义MediaPlayer 或MediaPlayer.OnPreparedListener?如果是这样,您还需要从 Proguard 中排除这些。比如:

-keep class android.media.** { *; }

【讨论】:

  • -keep class android.media.** { *; } 工作!非常感谢。我们的MHVideoPlayerModule 中有一个MediaPlayer.OnPreparedListener 的私​​有实例
【解决方案2】:

只需在您的“progaurd-project.txt”文件中插入以下行来检查它

-keep class android.widget.** { *; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 2021-07-19
    • 2018-04-08
    • 2019-05-07
    相关资源
    最近更新 更多