Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
590 views
in Technique[技术] by (71.8m points)

xamarin.android - NoClassDefFoundError: android/support/v4/content/LocalBroadcastManager

  • Platform: MonoDroid v4.2.4
  • IDE: Visual Studio 2012
  • Minimum SDK version: API 12

I'm having runtime issues when trying to utilize the LocalBroadcastManager class included in the Android.Support.v4.Content namespace. In my IDE, I've explicitly added the reference and can scope the namespace/class fine, and, after writing some code, compiles as expected. However, upon application deployment and launch, I'm prompted with the error: "NoClassDefFoundError: android/support/v4/content/LocalBroadcastManager"

Here's the code that prompts the runtime error (DSC_Discconected_From_Device is a class that inherits from BroadcastReceiver). It stops execution at the last line.

        IntentFilter filter = new IntentFilter(UsbManager.ActionUsbDeviceDetached);

        DSC_Disconnected_From_Device Receiver = new DSC_Disconnected_From_Device();

        LocalBroadcastManager.GetInstance(this).RegisterReceiver(Receiver, filter);

Under the SDK manager, all the API packages are installed, as well as the "Support Library" package under extras.

Where is it looking for the definition of the class? I've presumably copied the source, LocalBroadcastManager.java, to paths in the android-sdk framework where it "might" be looking. For example: ..android-sdkextrasandroidsupportv4srchoneycombandroidsupportv4contentLocalBroadcastManager.java

Ideas?

Edit: Forgot to mention that my project already references the support library, android-support-v4, in the folder "libs", located in the root of my project. I had to create the directory and add it through Visual Studio.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This problem was hounding me for almost six months now and no solution was helping me but today I have managed to find the correct solution on my own.

When you select your project target version to be greater than or equal to Android 4.0, Android SDK includes "android-support-v4.jar" file in your projects "libs" folder. This jar contains all the classes and methods related Android 4.0 or later.

Android is trying to find the class definition which is in "android-support-v4.jar" so that means you have not configured the build path to the "android-support-v4.jar" file. To do this, follow these steps:

  1. Open your project properties
  2. Select "Java Build Path" from left side menu
  3. Select "Libraries" tab
  4. Press "Add External Jar"
  5. (Most important step) Select "android-support-v4" jar file of "libs" folder from your CURRENT PROJECT LOCATION (path should be on your project folder and not the android sdk).
  6. Select "Order and Export" tab and "TICK" the checkbox of "android-support-v4.jar"

That's it, you're done!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...