ActionBarSherlock - The type android.support.v4.ap

2019-01-10 20:17发布

问题:

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?

回答1:

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.


回答2:

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.



回答3:

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.



回答4:

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



回答5:

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



回答6:

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



回答7:

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.


回答8:

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 }


回答9:

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.