Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R cannot be resolved error when using ActionBarSherlock

I am trying to use Jake Wharton's ActionBarSherlock to support actionbars in android projects all the way down to 1.6

I'm getting started using the video provided on the faq's page but after 2:25 in the video, when he imports the project, I get a whole huge list of >200 compilers errors, mostly dealing with some @override stuff. I fix most of those errors by:

Right click on the project>properties>Java Compiler>compiler compliance level: and I set it to 1.6.

This forces a re-build and suddenly I am down to just 54 errors. Most of them are "R cannot be resolved to a variable" but the last 5 are all "the import com.actionbarsherlock.R cannot be resolved". I have searched around and the common ways of solving this worked out as follows:

"Make sure your resources are not in error" -- I checked and there are no problems with anything in the /res folder

"Make sure you aren't importing android.R" -- I am not. I have:

import com.actionbarsherlock.R

It occurred to me that the package name might be incorrect, but it isn't.

"Simply clean the project" -- Have done this many times to no effect

"Make sure eclipse is able to generate R files at all" -- It can in the blank test project I made just now

And some other fixes which are more specific to ActionBarSherlock:

"Make sure your targetSDK is 11 or higher" -- It is set to 13

"Make sure the project is a library project" -- It is

How can I get rid of these errors?

like image 919
MattF Avatar asked Jan 09 '12 10:01

MattF


4 Answers

Found it!

Instead of:

Project > Clean > Clean Projects Selected Below

you must use

Project > Clean > Clean All Projects

Even if none of the other projects have anything to do with the library project. This fixed the problem

like image 141
MattF Avatar answered Oct 17 '22 20:10

MattF


My fault was, that the ABS-project and my project had different API levels. ABS was on level 4.0.3 and my project had 3.0. After changing the API level of my project to 4.0.3 all errors were fixed. This post helped me to find the solution.

like image 24
uldo Avatar answered Oct 17 '22 21:10

uldo


Might also need to make sure your nen/R.java file is created for the right package name:
On AndroidManifest.xml, make sure the manifest tag, package attribute is set to:

"com.actionbarsherlock"

like image 2
Gili Nachum Avatar answered Oct 17 '22 20:10

Gili Nachum


Instead of importing the single folder actionbarsherlock, I ended up picking the parent folder and unchecked everything but actionbarsherlock in the Import Projects window.

enter image description here

like image 1
Massimo Fazzolari Avatar answered Oct 17 '22 20:10

Massimo Fazzolari