Cannot resolve symbol 'R' in android Studio - java

I know this may sound like a duplicate, but I have read and tried avery answer posted here. It is just not working for me.
What do I need to do to fix this?
only android.R is working , I can't use R directly. I have been hunting the solution for few days. I didn't really wanted to go back to eclipse but I wasted a lot of time already trying to resolve this.
any idea?
Things I tried:
clean gradle
Sync gradle
Checked for xml errors
Answer below
and more....

Things to do:
Be sure you delete any stray imports lines that are pulling in android.R or any other package.R, then re-ruild/clean restart eclipse/android studio.

I had the same issue when I tried importing an existing Eclipse Android Project into Android Studio. The issue was resolved when I removed the following code in the build.gragle file :
here is the code
`dependencies {
classpath 'com.android.tools.build:gradle:0.4+
}`

Related

Deleted the .project file in the eclipse workspace

I had a problem with eclipse (mars) on my android project so I looked it up and found this question, I followed the first answer and they made me delete the .project file (which is located in workspace\.metadata\.plugins\org.eclipse.core.resources\.safetable) when I tried to paste it later it was gone. Now I'm getting a lot of errors in eclipse when I try to do stuff like run the project. Is there any way to recover it? Or is there a duplicate I can download from somewhere?
Any help would be appreciated.
Thanks,
If i were you i would upgrade to android studio.
You can try to import your broken project and maybe android studio will fix it for you. Since android studio works with Gradle builds it might fix just that.

Error in my R.java file cannot be resolved

I am using the Eclipse ADT bundle and recently updated my Android SDK tools and Android SDK platform tools then thereafter I tried creating a new project and I keep getting an error in my R.java file that seems trivial but I still dont understand how it keeps showing up since it is an autogenerated file.The error is: Syntax error, insert "}" to complete ClassBody. Keep in mind this is when I have just created the project. Also deleting the file and letting it autogenerate still yields the same result that is the error.Please help on how I can solve this,can't seem to find any links to a newer ADT bundle.This error shows up in the console: ERROR: In MenuView, unable to find attribute android:preserveIconSpacing
Navigate to \Android.Support.v7.AppCompat\2x.x.x\content\support\v7\appcompat\res\values\attrs.xml in side your project directory.
or
open the AppCompat project in your workspace and navigate to \res\values\attrs.xml
Find "android:preserveIconSpacing" in attrs.xml file and and comment that line.
Rebuild the project again.
Hope this solves the issue.
i did comment "android:preserveIconSpacing" but generate more error.
i have back up appcompat_v7 and replace it with broken one and every thing goes right again .
This problem occurs when you update the ADT. So it is recommendable to use Android Studio.
If that doesnt work then try what #Harsh Dattani stated in the previous answer which is to Clean or Rebuild the project.
i think it's SDK Manager-Tools not installed.

Why am I getting 'R cannot be resolved to a variable' on a previously working project(JAVA 8)?

I know that it has been asked thousands of times, but I really can't fix this at this momment. I'm trying to update an old project(already submitet to the play store). The only dependency was the v7 appcompact lybrary and so I added it to the new workspace and updated the existing project dep[endencie, but I'm still getting the strange R cannot be resolved to a variable error.
Here is what I'm doing and even if I'm 99% sure that it is what I have to do, it's not working.
Updating the project dependencie:
everything looks nice, but when I clean and rebuild the project, here is what happens:
and the problem is still there. I'm really going to start crying, because it was a working project, buta after switching to a new workspace and checking it out from my git repository, I can't get it working.
Do you have an idea what is going on? I know that I miss something small here, I know that it has been asked so many times, but I can't find an answer fitting on my case.
Remove library project android-support-v7-appcompact and add it again properly.
also check your package name in manifest file.
update SDK Build Tools on SDK Tools -> SDK Platform Tools, if not, please try it and clean & rebuild.
check imports to see any broken R.java imports. if there is "import android.R;" remove it.
check style and layout xmls to prevent any missing drawables or depreciates.
also see : R cannot be resolved - Android error
Just to tell my experience with this problem in a Java project with JDK8. In my case I was running the project in a Mac with Yosemite. Reading the specs. Android Studio and SDK, I've found that projects could be compiled up to Yosemite version.
I changed my environment variables to JDK7 and it worked!

Android - What happen to my Project?

I am new to android development. Yesterday night I was working on my project. It was working well. But today morning I open my project I got R error. Then only I noticed my project everything is disabled.
I don't know what is happening. Please help me to resolve this problem.
You need to clean and build your project, and if that didnt work you need to check your manifest and style folder for any error that sometimes it wont hint you for errors in there.
It happened to be before, I had some issues with Java x64 and Android SDK, I couldn't fix it and someone told me to switch java, eclipse and sdk to 32 bits.
This was around 6 months ago, dont know if its the same problem.
This error occurs due to the change in the path of the library required by the Project.
Go in the Java Build Path option and try to remove and add again the library.
Tick the android sdk package name in project properties.
Finally I changed the workspace. It is working. But still now I don't know why all my folders are closed in my previous Workspace.. Thanks to all..

R.Java not showing up

I've tried everything i can think of and i still can't get the R.java file to show up.
It's supposed to be in the "gen" folder in eclipse when i create a new project i believe.
I tried the following:
I went to Project > Clean...
I heard that there might be issues in the xml files, i couldn't find any errors there.
I tried using both android 2.1 and 2.2(my goal is to program in 2.2 but i tried both anyway).
Please help. I've seen a few other questions regarding the same issue on here; i've tried using the suggestions found in the answers to those questions but unfortunately, no luck.
Progress: 1
SOLVED: I found out i was missing Android SDK Platform Tools. If you're having the same problem, make sure you have it installed.
Go to Window > Android Sdk and Avd Manager > Available Packages > Android Repository > Android SDK Platform Tools(the latest version) > Install. Sorry for causing any confusions. I will one-up those who put some effort into helping me. Thank you very much for your efforts. :)
Try a right-click on the project and select "Refresh". This usually does the trick for me when "Clean" does not.
you shall find the answer here..tat works for me. just try...
R file is missing android
I have faced the same problem many times untill and unless u wont remove errors from ur
xml file or any java file.
Then clean uo ur project....
Cleaning of project wont work in case there is errors,plz check for the same
if above option not working then try project->built automatically checked then clean project then try to run it

Categories