Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError for VideoView.setOnPreparedListener()

I am having trouble with Proguard and my custom VideoView for my app. It seems as though obfuscating my code causes issues with my VideoView. Whenever I try to set the OnPreparedListener for the video, my app crashes. See:

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)
        ...

I have tried adding the below lines to the Proguard file, but they don't help.

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

EDIT: Here is the proguard-project.txt file:

# 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
like image 412
Bryan Sills Avatar asked Nov 13 '14 22:11

Bryan Sills


2 Answers

It appears you are also providing a custom android.media.MediaPlayer and/or android.media.MediaPlayer.OnPreparedListener implementation:

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 -- The method you are calling

(L -- The smali prefix for Objects

android/media/MediaPlayer$e -- The actual type name you are trying to pass in to the method. This is the problem. The inner class type OnPreparedListener is getting obfuscated. It should be android/media/MediaPlayer$OnPreparedListener

android/widget/VideoView the class that is attempting to host this method signature.


Do you have a custom MediaPlayer or MediaPlayer.OnPreparedListener that uses the original package names? If so, you also need to exclude those from Proguard. Something like:

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

like image 136
Jeffrey Mixon Avatar answered Oct 08 '22 10:10

Jeffrey Mixon


just check it out by inserting below line in your "progaurd-project.txt" file

-keep class android.widget.** { *; }
like image 36
Mohsin Bagwan Avatar answered Oct 08 '22 10:10

Mohsin Bagwan