6

I know there are a lot of threads about this but I couldn't find one that solved my problem or is a duplicate.

So I was working on an app, accidently made the mistake of cleaning my project. This caused my R.java file to disappear. I tried cleaning my project again, building it again, closing eclipse, deleting the gen folder, checking all of my xml files for errors, all of that.

Problem now is whenever I create a new completely blank application project that doesn't even generate an R file automatically. I'm hoping there is still a way to restore it for my original project but as I stated nothing seems to work.

Tala
  • 8,298
  • 4
  • 30
  • 35
Ryan Sayles
  • 3,277
  • 11
  • 49
  • 79
  • 1
    Updated to ADT R22? Do you have the Build-tools package installed? (Check in SDK Manager). – laalto May 24 '13 at 13:32

16 Answers16

12

It could be if you have deleted

  <string name="action_settings">Settings</string>

in the strings.xml, but not deleted main.xml file in the menu folder.

Andrew
  • 31,284
  • 10
  • 129
  • 99
  • 2
    Man I accidentally deleted the whole strings.xml and then there came a troop of errors. I was banging my head for half an hour trying to figure out why was R file not generating. Than I saw your answer and realize that my Strings.xml was not there. Thanks to you man. – Rakesh May 10 '14 at 14:01
  • For me was that! Thanks very much. – Boris Karloff May 23 '14 at 01:11
7

have you tried checking for the target API maybe the api is low try doing right click your project >> properties >> andriod >> check the correct API or check if there are any error and fix them first these steps made my r file generate hope it makes yours

Giant
  • 1,571
  • 5
  • 30
  • 62
  • I have tried that, min is still at 4.0 and target is still at 4.2. It was working fine, I didn't change anything and I cleaned it which caused the error. The only errors coming up are the ones that try to reference R.something since R doesn't exist. I'm still more confused as to why it won't even generate when I create a new project – Ryan Sayles May 24 '13 at 02:18
  • are you using eclipse in your project? – Giant May 24 '13 at 02:28
  • i cant think of any other solution but try this link out http://stackoverflow.com/questions/2194808/debug-certificate-expired-error-in-eclipse-android-plugins?rq=1 maybe it can solve your problem – Giant May 24 '13 at 02:41
3

I have just had this experience. In my AndroidManifest.xml there was a reference to a theme which didn't exist.

For instance.

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme_Lorem" >

There wasn't AppTheme_Lorem among the application's themes

Maksim Dmitriev
  • 5,313
  • 9
  • 57
  • 124
2

If newly created projects doesn't generate R.java file, most probably the adb is not running.

Solution:

  1. Make sure, there is an executable file named adb at /SDK folder/platform-tools/adb
  2. If you are on Linux platform, make sure it is not locked and is executable.

    Right click on adb -> permissions -> Tick on the check box "Execute/Run as a program".

Nizam
  • 5,506
  • 9
  • 40
  • 54
1

If any resource file name contains Caps Letter means doesn't generate R.java file. Otherwise you can modify some changes or put space in Android Manifest file and save the project. If it is not generated means you can use project clean or close the editor and reopen it. It will work.

Bebin T.N
  • 2,409
  • 1
  • 21
  • 27
1

I had the same issue. In my drawable folder I added a file video_Icon.jpg after that eclipse was not able to generating R file.

To fix the issue I changed the file name to video_icon.jpg and it worked.

gniourf_gniourf
  • 38,851
  • 8
  • 82
  • 94
1

If none of the solutions above works, you could right click on your project, go to Android Tools and select Run Lint: check for common Errors. Generally it's something in your xml files that stops the R file from being regenerated and the worst part is that there are some errors that are not signaled as being "errors". In my case there was a problem with naming the images in the drawable folder...as a piece of advice for beginners, don't use camel case for xml variables (image names buttons etc)

vzR
  • 1,148
  • 1
  • 10
  • 14
0

This can happen if you've recently updated your SDK tools to version R22. This answer discusses the solution: check all of the boxes in the order/export tab of the Java Build Path for the project and each library.

Community
  • 1
  • 1
dhaag23
  • 6,050
  • 33
  • 35
0

First if you use R22, try to downgrade it to R21. I tried R22 a few days ago and it really messed me up, we should wait for another stable one. Then click on you project and press F5 to refresh it, sometimes Eclipse just wanna mess with you.

DucTran
  • 156
  • 1
  • 12
  • I have same problem, and i think problem is with my java. I can not open SDK Manager to downgrade and even I installed Android Studio, that also does not launches successfully. Just crashes instantly.. – Rizwan Sohaib May 24 '13 at 06:51
  • @Rizwan: there are some people cannot open their SDK Manager when they use Android Studio. I don't use it but I come across some questions about that already, it seems like Android Studio is also having some problems. Lucky me that I'm using 2 "different machines", one 1 my real windows and the other is on Hyper-V and I still keep the source for R21. I just uninstalled R22 on my real one then copy the R21 from the Hyper-V to it. You should try to find a R21 source somewhere, uninstalled everything android-related (e.g .android folder) and install the R21. – DucTran May 27 '13 at 07:26
0

Re-install ADT bundle. Worked for me.

M.Salomaa
  • 63
  • 7
0

Check if there is import android.R;

Don't use android.R here, use a fully qualified name for each usage instead

MSIslam
  • 3,991
  • 5
  • 22
  • 27
0

Sorry for the late reply but I thought this could give insight to anyone that has this problem.

When the R file isn't generated it generally means that there is a problem with one of the layouts. It could refer to the manifest file having syntax errors or one of the layout files itself.

Another reason could be that an image file contains upper case letters. Change it all to lower case, and use an underscore instead of a space in the file name of images.

Ushal Naidoo
  • 2,666
  • 1
  • 21
  • 37
0

This helped me, install Intellij IDEA IDE community edition and open eclipse android project. For me Intellij showed errors in my res files which was not shown by eclipse.

I solved issue using Intellij. though after solving issue i am again using Eclipse.

I Tried every answer though can't solve the problem.Finally Intellij IDEA IDE helped. It was right that there was problem in resource files.

Adhikari Bishwash
  • 2,570
  • 25
  • 31
0

Try Following step may be it helpful for you or other :

  • Make sure that anything the R links to is not broken. Fix all errors in your XML files.

  • If anything in the SDKs are broken, R will not regenerate.

      If you somehow hit something and created import android.R in your
      activity, remove it.
    
      Run Project -> Clean. This will delete and regenerate R and
      BuildConfig. Make sure Project -> Build Automatically is ticked. If
      not, build it manually via Menu -> Project -> Build Project.
    
      Wait a few seconds for the errors to disappear. If it doesn't work,
      delete everything inside the /gen/ folder If it still doesn't work,
      try right-clicking your project -> Android Tools -> Fix Project
      Properties. Check your *.properties files (in the root folder of
      your app folder) and make sure that the links in there are not
      broken.
    
      Right-click your project > properties > Android. Look at the Project
      Build Target and Library sections on the right side of the page.
      Your Build Target should match the target in your
      AndroidManifest.xml. 
    
      So if it's set to target 17 in AndroidManifest, make sure that the
      Target Name is Android 4.2. If your Library has an X under the
      reference, remove and re-add the library until there's a green tick.
      This might happen if you've moved a few files and folders around.
      What to do if R doesn't regenerate
    
      This usually happens when you have a broken xml file.
    
      Check errors inside your XML files, mainly within the /res/ folder
      Common places are /layout/ and /values/ especially if you've changed
      one of them recently Check AndroidManifest.xml, 
    
      I find that often I change a string, and forget to change the string
      name from AndroidManifest.xml. Check that Android SDK Build-tools is
      installed. Window->Android SDK Manager->Tools->Android SDK
      Build-tools
    
      Make sure when you update the Android SDK Tools, you also update the
      Android SDK Platform-tools and Android ADK Build-tools. 
    
      Build fails silently if they don't match.
    
      If you can't find the issue, right click /gen/ -> Restore from local
      history... -> tick R.java -> click Restore. 
    
      Even if it doesn't solve the problem, but it will clear out the
      extra errors to make the problem easier to find.
    
Karthikeyan
  • 168
  • 2
  • 10
Nirav Mehta
  • 1,677
  • 4
  • 23
  • 41
0

Check the path of the files under /your project/res/ folder for images or any other resource in this folder and correct them.

Celeo
  • 5,017
  • 8
  • 35
  • 39
-2

That happened to me, too. I checked layout xml files and discovered that, if you are giving position reference of a widget (for example a button) with respect to another one in GLE(Graphical Layout Editor), then this line of code is generated by Eclipse in xml automatically but sometimes with errors, that it forgets "+" sign for referencing. like:

>>> (hand corrected) android:id="@+id/......"

solved problem for me....