Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 789
znat Avatar asked May 16 '13 13:05

znat


5 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.
like image 53
Sébastien BATEZAT Avatar answered Nov 15 '22 08:11

Sébastien BATEZAT


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.

like image 11
endowzoner Avatar answered Nov 15 '22 09:11

endowzoner


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.

like image 10
Carlos Avatar answered Nov 15 '22 09:11

Carlos


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

like image 8
SpeedEX505 Avatar answered Nov 15 '22 09:11

SpeedEX505


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

like image 4
Ahsanwarsi Avatar answered Nov 15 '22 09:11

Ahsanwarsi