Android Chomecast Sender App: MediaRouteActionProv

2019-08-03 06:19发布

问题:

I have a problem with a Chromecast sender app for Android. This is my second sender app so, generally speaking, I have the basics down.

What is right:

When I run the app directly from Eclipse, it works on both of my test devices. When I run the app directly from Android Studio, it works on both of my test devices.

The problem:

When I generate a signed APK through BOTH Eclipse and Android Studio, the app crashes when it reaches the “cast activity” on both devices.

The logcat error is as follows:

07-04 12:39:54.887: W/SupportMenuInflater(31144): Cannot instantiate class: android.support.v7.app.MediaRouteActionProvider
07-04 12:39:54.887: W/SupportMenuInflater(31144): java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.MediaRouteActionProvider" on path: DexPathList[[zip file "/data/app/com.victuallist.shred-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.victuallist.shred-1, /vendor/lib, /system/lib]]
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v7.internal.view.f.a(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v7.internal.view.f.b(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v7.internal.view.d.a(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v7.internal.view.d.inflate(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at com.victuallist.castgame.CastGameActivity.onCreateOptionsMenu(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v4.app.k.onCreatePanelMenu(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v7.a.g.a(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v7.a.n.a(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v7.a.g.onCreatePanelMenu(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.support.v7.a.o.onCreatePanelMenu(Unknown Source)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.view.Choreographer.doCallbacks(Choreographer.java:574)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.view.Choreographer.doFrame(Choreographer.java:543)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.os.Handler.handleCallback(Handler.java:733)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.os.Handler.dispatchMessage(Handler.java:95)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.os.Looper.loop(Looper.java:136)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at android.app.ActivityThread.main(ActivityThread.java:5001)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at java.lang.reflect.Method.invokeNative(Native Method)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at java.lang.reflect.Method.invoke(Method.java:515)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-04 12:39:54.887: W/SupportMenuInflater(31144):   at dalvik.system.NativeStart.main(Native Method)
07-04 12:39:54.897: D/AndroidRuntime(31144): Shutting down VM
07-04 12:39:54.897: W/dalvikvm(31144): threadid=1: thread exiting with uncaught exception (group=0x41611ba8)
07-04 12:39:54.897: E/AndroidRuntime(31144): FATAL EXCEPTION: main

UPDATE: It seems that I have it working. I disabled proguard. Despite having it running, I am still interested in knowing why I encountered the problem. Any tips would be appreciated. Thanks.

回答1:

add 3 lines to your proguard file ...

-keep        class android.support.v13.** { *; }
-keep        class android.support.v7.** { *; }
-keep        class android.support.v4.** { *; }

will solve class not found issues in all the support libs.



回答2:

ProGuard does not examine things like menu resources to try to find classes that need to be free from obfuscation. Any classes that you reference from resources need to be left untouched, typically by some flavor of a -keep directive in your ProGuard configuration.

What probably happened is that ProGuard obfuscated MediaRouteActionProvider, so your code compiled, but then Android could not find the class by its un-obfuscated name.