Search code examples
androidactionbarsherlock

import .R cannot be resolved when I import actionbarsherlock


I want to be able to use the action bar in my android project (2.3), so I am trying to import the actionbarsherlock library. However, I am having problems....

I've imported the library, edited the build path of my android project to include the library, and also deleted the android-support-v4 jar from the ABS /libs directory and copied my project's android-support-v4 into the ABS /libs directory to solve the jar mismatch. However, now that I've done all those things, my project can't resolve myproject.R anywhere. I import myproject.R in almost all of my .java files, and they all have the same error ("The import com.myproject.R cannot be resolved"). In addition, when I clean my project, I get a lot of errors in the console window:

They all go along the lines of:

error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light'.

To my knowledge, R is where all of the layout information is stored, so I have no idea why this is even a problem...

I've been working on this error for days, and I'm extremely frustrated and finally decided to take it to stack overflow. Thanks guys for the help!


Solution

  • edited the build path of my android project to include the library

    Never manually modify the build path of an Android project.

    ActionBarSherlock is an Android library project. You need to add a reference to ActionBarSherlock's library project from your main application project and undo the manual change to the build path.


    UPDATE

    The second half of your problem was that your build target was set too low. The build target controls what version of the Android classes, resources, etc. is available to your app, and if you use ActionBarSherlock, you need this to be API Level 14 or higher.

    if I make my project build target 4.0, can I still run it on an emulator/phone running Android 2.3?

    Yes. Set your android:minSdkVersion to be 10 or lower. Eclipse (via Lint) will yell at you if you accidentally try using classes, methods, and such that are higher than your minSdkVersion, even though they are legal due to your build target.