问题
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.
回答1:
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.
回答2:
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
回答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
回答4:
If newly created projects doesn't generate R.java file, most probably the adb is not running.
Solution:
- Make sure, there is an executable file named adb at /SDK folder/platform-tools/adb
- 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".
回答5:
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.
回答6:
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.
回答7:
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)
回答8:
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.
回答9:
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.
回答10:
Re-install ADT bundle. Worked for me.
回答11:
Check if there is import android.R;
Don't use android.R here, use a fully qualified name for each usage instead
回答12:
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.
回答13:
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.
回答14:
Check the path of the files under /your project/res/
folder for images or any other resource in this folder and correct them.
回答15:
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.
回答16:
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....
来源:https://stackoverflow.com/questions/16726544/android-r-file-not-generating