Where do I find android.support.v7.mediarouter.R$a

2019-06-23 05:27发布

问题:

Short version

I'm getting an unhandled exception when instantiating an android.support.v7.app.MediaRouteButton object. I get:

NoClassDefFoundError: android.support.v7.mediarouter.R$attr

Where is this class? Or if it's auto-generated, how do I get it to auto-generate?

Longer version

I am following along with the tutorial for Android app development for chromecast found here: https://developers.google.com/cast/cast_2nd-screen_app_tutorial

I am developing using the ADT bundled eclipse, on ubuntu 13.04.

I imported the following jar files into a libs directory right in my workspace and have included them in my Java Build Path via "Add Jars..." button in the "Libraries" tab of the "Java Build Path" panel of my project's properties:

  • GoogleCastSdkAndroid-1.0.0.jar
  • android-support-v4.jar
  • android-support-v7-appcompat.jar
  • android-support-v7-gridlayout.jar
  • android-support-v7-mediarouter.jar

I have a single activity (the default "hello world" created by Eclipse), and have not modified the layout. The only code I need to add to cause the error (pasted below) to show is this:

import android.support.v7.app.MediaRouteButton;
...
MediaRouteButton mrb = new MediaRouteButton(this.getApplicationContext());

When I build and run the app I see the error message pasted below in LogCat (I can post more of it if anyone feels it's relevant). The key things I notice are that I seem to be missing android.support.v7.mediarouter.R$attr (NoClassDefFoundError), and that it is being called from android.support.v7.app.MediaRouteButton's constructor

08-12 00:36:02.837: E/AndroidRuntime(29600): java.lang.NoClassDefFoundError: android.support.v7.mediarouter.R$attr
08-12 00:36:02.837: E/AndroidRuntime(29600):    at android.support.v7.app.MediaRouteButton.<init>(MediaRouteButton.java:117)
08-12 00:36:02.837: E/AndroidRuntime(29600):    at android.support.v7.app.MediaRouteButton.<init>(MediaRouteButton.java:113)
08-12 00:36:02.837: E/AndroidRuntime(29600):    at com.jeffbmartinez.helicast.MainActivity.onCreate(MainActivity.java:31)
...

The fact that it is running the MediaRouteButton's constructor leads me to believe the jar files are being properly found so I don't think I misconfigured eclipse in relation to the dependencies (jar files). However, my understanding is that these 'R' files are auto-generated. If this is correct, where is my android.support.v7.mediarouter.R file? I do not see it in the gen directory, which where com.jeffbmartinez.helicast.R file is being placed.

Furthermore, I find it curious that the MediaRouteButton refers to a package name that I cannot find in any of the 5 jar dependencies listed above. android-support-v7-mediarouter.jar contains only android.support.v7.app.* and android.support.v7.media.*.

The only place I find reference to android.support.v7.mediarouter, aside from my error logs, is at https://developer.android.com/reference/android/support/v7/mediarouter/package-summary.html but there is little information there.

Am I missing a dependency? If so, where do I get it or how do I generate it?

Thanks!

回答1:

You can't just include the jars. You need to add the android.support.v7.mediarouter project as a Android Library dependency. That way, the resources from the project will get merged into your own.

Inside the mediarouter folder run android update lib-project -p . and then you can add it as a dependency.



回答2:

In order to avoid any XML compilation errors just configure the build path to resolve to ANDROID API 17 (e.g Project > Properties > Android in Eclipse )