ActionBarSherlock - The type android.support.v4.app.Fragment cannot be resolved. It is indirectly referenced from required .class files

I am using ActionBarSherlock as a library project in a project which is a library itself. It was all working fine until I moved the project to a new computer and updated the SDK tools.

I have this error I don't understand. When I create a class extending SherlockFragment like this:

import com.actionbarsherlock.app.SherlockFragment;

public class SomeFragment extends SherlockFragment {
    ... 
}

I have the following compilation error:

The type android.support.v4.app.Fragment cannot be resolved. It is indirectly referenced from required .class files

I have checked the following:

  • ActionBarSherlock is imported as a library
  • No apparent errors in build path (no red cross) and actionbarsherlock.jar is present
  • The support library is in the ActionBarSherlock project and NOT in other depending projects

Anything else?

Answers


I had the same problem as you since I had updated the SDK. I have solved my problem by doing this (on eclipse) :

  • Right click on the action bar sherlock library => Properties => Java Build Path => Order and Export tab => check android support v4 or Android Private Libraries and select Ok
  • Right click on your personal project and go to properties => java build path => check Android Private Libraries
  • Clean both projects, it should work.

Sebastien's answer actually led me to the solution. However, it is important to mention that the support library has to be added manually to the build path in order to be able to check it for exporting. For future reference, here are the steps that solved the problem for me:

  1. Make sure the support library is in the libs folder of the ABS project and nowhere else
  2. Right-click on the library --> Build path --> Add to build path
  3. Right-click on ABS project --> Properties --> Java Build Path --> Order and Export --> Check the android-support-v4.jar file and save
  4. Right-click on the project where you have included ABS --> Properties --> Java Build Path --> Order and Export --> Check the "Android Private Libraries" and save
  5. If you have additional projects in your dependency hierarchy, do step 4 for all of this projects
  6. Clean the entire workspace (or all affected projects) and hope the best.

However, it is a mystery for me why this has to be so complicated - as Josh mentioned, Eclipse in combination with Android and large projects with a couple of dependencies is hard to use and I hope this will be improved in near future.


In my case I'm using 2 Android libraries which require the android support library. The problem was that both libraries had different versions of the Android support library.

To resolve the issue: Right click on the library project => Android Tools => Add Support Library.

Repeat this action for each library.


I had same problem. There were 2 different libraries. Delete support library from your main project


Here is simplest solution:

Right click on your project folder -> Build path -> Configure build path -> Add External Jars(From libraries tab) -> select "android-support-v4.jar" file.

(It'll be located in Android SDK folder here is generic path "android-sdk\extras\android\support\v4").

After this clean you project and happy coding...


I faced the same problem in my case i resolved it by right clicking on the project -> Buid path -> Configure Build path -> "select Android from left hand list" -> "select the check box for build project target from the right hand panel" -> click Apply -> click Ok


What worked for me was a little different than the solutions by @Sebastien and @FleshWound above in the thread.

  • Copied the file "android-support-v4.jar" from /MyProject/libs/ and overwrote the one at /ActionBarSherlock/libs/android-support-v4.jar.
  • Went to "Project Properties" -> "Java Build Path" -> "Add" -> ActionBarSherlock project.
  • Clean project.

I was using Android Studio and faced with similar problem(for loading ListFragment). I had initially imported library:

import android.support.v4.app.ListFragment;

And then updated build.gradle inside app diectory: Make sure dependencies section includes support libraries-

  dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0 }

I am new to stackoverflow. However this is my solution or experience here. I solved this by Project Properties--> 'Android' on the left Panel -->Add--> Select the required support library from the drop down menu-->'Apply'-->OK

This got it done. This worked even when 'Android Private Libraries' was unchecked from 'Order and Export' of Java Build Path.


Need Your Help

Rails how to run rake task

ruby-on-rails ruby rake

How do I run this rake file in terminal/console?

Get date and time when photo was taken from EXIF data using PIL

python python-imaging-library exif

I can get the EXIF data from an image using PIL, but how can I get the date and time that the photo was taken?