android – NoSuchMethodError for VideoView.setOnPreparedListener()

前端之家收集整理的这篇文章主要介绍了android – NoSuchMethodError for VideoView.setOnPreparedListener()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的Proguard和我的自定义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

解决方法

看来你还提供了一个定制的android.media.MediaPlayer和/或android.media.MediaPlayer.OnPreparedListener实现:

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)

setOnPreparedListener – 您调用方法

(L – 对象的smali前缀

android / media / MediaPlayer $e – 您尝试传入方法的实际类型名称.这就是问题.内部类型OnPreparedListener正在被模糊化.应该是android / media / MediaPlayer $OnPreparedListener

android / widget / VideoView尝试托管此方法签名的类.

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

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

猜你在找的Android相关文章