73

I have updated my SDK and ADT to the latest version, I have also update the Eclipse to Kepler the latest one after Juno.

My ADT version is 22.0. After this update when I create a new project, I'm getting error, stating R cannot be resolved to a variable. I have imported import android.R;, but it is showing as unused import stating Don't include android.R here; use a fully qualified name for each usage instead.

Same thing is happening with Mac OS also with the latest update. I have tried renaming activity_main.xml to other name, but still my R.java is not generated.

Tried all the things which are possible. Cleaned the project, build the whole workspace. Nothing helping.

I think ADT or Eclipse compatibility is having problem after the update.

I have updated my whole SDK, here is the screenshot, but same problem is there.

enter image description here

Anupam
  • 3,742
  • 18
  • 55
  • 87
  • 1
    Have you checked all your xml layout files? Because errors in layout files may cause this problem. – Basim Sherif May 17 '13 at 12:04
  • You NEVER want to import `android.R`, but it sounds like you have removed it already and cleaned the project... so this is a problem... – TronicZomB May 17 '13 at 12:04
  • Check is there any problems showing the problems window – Pragnani May 17 '13 at 12:05
  • you could give the accepted answer in the link a try. http://stackoverflow.com/questions/16583118/google-maps-api-v2-class-not-found/16583424#16583424 – Raghunandan May 17 '13 at 12:07

14 Answers14

171

After updating to SDK Tools to rev. 22 for the first time, you may need to relaunch Android SDK Manager again and install a new item: Android SDK Build-tools. enter image description here

After installing this, clean your projects and rebuild.

Krauxe
  • 6,058
  • 2
  • 24
  • 22
  • 3
    Thanks dude, after installing I restarted my system, now it is working fine. – Anupam May 17 '13 at 12:20
  • 1
    ...can't wait to start using IntelliJ...and I hope performing SDK/ADT updates won't be as much of a headache as it's been with Eclipse! – dell116 May 24 '13 at 16:36
  • If your SDK window is missing, see here: http://stackoverflow.com/questions/4649562/eclipse-with-android-sdk-missing-menu-items – totaam Jul 09 '13 at 05:36
  • Thx, I spent half a day in this damn sdk and adt update. Reopen eclipse suffices, no need reboot pc. – macio.Jun Jul 09 '13 at 20:11
  • +1. I encounter this problem just now. added to this, my recent project still having red marks on lines in the code. The fix is to "Right-Click on the project>Android Tools>Fix project properties". :) – XBasic3000 Jul 17 '13 at 09:03
  • @Krauxe. Thank you very much! Once Eclipse was updated, all projects became a disaster. You really save my day! Haha – user1914692 Aug 29 '13 at 21:07
  • Thanks...this was keeping Eclipse from starting up properly...was just stuck on updating ADK library in the pending jobs list :-P – kenyee Oct 15 '13 at 14:09
  • 2
    Can someone point me to an official source for when they announced this new item (*Android SDK Build-tools*)? It's so ridiculous they they don't give us any heads-up about changes like this. – Tony Chan Dec 13 '13 at 02:35
  • I had the same as mentioned problem, I tried doing your suggestion, found a no of SDK build tools. I installed 3 of them revision - 17, 19 and 21.1.1, but none of them seemed to work, I even restarted eclipse twice and restarted machine once, but that too didn't help me out – Narendra Singh Nov 16 '14 at 21:13
6

Yesterday, I made an update with sdk manager, and I had the same problem as you. I fixed the issue: I have updated another time the android sdk (with the sdk manager tool), then I check update from eclipse for install the updated ADT plugin and I rebuid my project. "Android sdk Build-tools" from Android sdk manager is now rev 17 and now it is OK. I think the issue is from adt plugin from eclipse

Jarvis
  • 1,527
  • 12
  • 17
2

import android.R - remove this statement from all your classes and then do a clean your R file will be generated. if this did not work then check all your xml files for any errors and then do a clean. These 2 are the most common reasons for R file to go missing

prvn
  • 916
  • 5
  • 5
1

Changes in your Build target also can effect R.java in Eclipse so

Right Click Project >> Properties >> Android >> Select Latest(usually) Android API Platform >> Click OK

Hope this is helpful.

1

Follow These steps...

  1. Right Click Your Project.
  2. Select Properties->Android Check Project Build Target and API Level.
  3. Again come back and open Android Sdk Manager Chekc the Tools and make sure you are installed Curresponding Android SDK Build Tools.

Eg : IF you selected api level 17 in properties you should install Android SDK Build Tools 17..

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
shihabkv
  • 41
  • 2
  • This seems to suggest what the top answer already suggested...Did you Google for the answer and find it on StackOverflow, and then come back and post it here ;-) – AndyG Mar 15 '14 at 06:54
0

Try this:

  1. make a backup of your projects on desktop

  2. close eclipse

  3. delete your workspace

  4. restart eclipse and import your projects again.

JRE.exe
  • 801
  • 1
  • 15
  • 28
0

I had same problem.. I solved by doing the following:

  1. check all xml files and drawable files if there are any CAPITAL LETTERS in file name, if you have then change it to lower case, if you are using selector xml files then check the other files you are linking in those files..all should be lower case.

  2. Go to java files which show error and remove IMPORT R.java file from imports list.

  3. Go to Projects>>Clean.

This should fix the problem. This is how i fixed :)

Murli
  • 524
  • 6
  • 11
0

My issue was that I had android:orientation misspelled in my activity_main.xml file and I was getting this error. I fixed the spelling and problem went away! So make sure activity_main.xml doesn't have any errors in it.

Micro
  • 10,303
  • 14
  • 82
  • 120
0

Sometimes when you extract your file it miss some part so better when its extracting make sure all file are extracting properly and then run eclipse after that run a simple file and install plugin of avd it helped in my case

Himanshu Gupta
  • 69
  • 1
  • 10
-1

if the problem persists then try closing the other projects by

right click -> close Unrelated projects !

this worked in my case

Vivek Warde
  • 1,936
  • 8
  • 47
  • 77
-1

For eclipse users: Comment the lines including R.* Clean and build. R.java will be generated and then uncomment the R.* and rebuild.

Dhruv Kohli
  • 101
  • 2
-2

the best solution for r.java missing for linux... R.java is self generated in gen folder.. so better dont edit or create manually by urself ..

-open terminal(alt + ctrl + t) -change directory to skd->tools -then provide executive attribute to all executable file by(sudo chmod +x filename) -do the same for files in sdk->platform tools .. (ie sudo chmod +x filename) .. -----every executable file sud b provided with +x attribute...

-2

just delete gen folder all of your error will be cleared

-2

Proven successful method, check the file (AndroidManifest.xml) and delete all comments in it, and make sure there are no errors in this file, I tried and did work with me.