Android Studio cannot resolve R in imported project?
Solution 1
- Press F4 into Project Structure, Check SDKs on left
- Click Modules ---> Source Tab, check gen and src as sources
PS: The answer over a year old and the menus have changed.
Solution 2
File -> invalidate caches
then
Restart application
Solution 3
None of the answers on the web so far have helped. Build > Make Project did not work for me. For me it was as simple as choosing this other option (on Android Studio 1.3.1):
Build > Make Module 'module name'
Solution 4
In my case I had an Activity file imported from Eclipse that had the line:
import android.R;
So all of my R classes were resolving to the SDK, as soon as I commented out that line everything compiled correctly to my package. I only noticed the issue when I was moving the project from my Mac to my Windows machine.
Solution 5
This issue starting occurring for me when I started working with build.gradle to incorporate the data necessary (signingConfigs) to build a signed .apk. After what appeared to be a successful build from the command line, I discovered that going into any class using R.* that all R.* references were unresolved.
The answers here didn't help me. I decided to re-import the project and it magically fixed the issue. File/Import Project... and select the build.gradle file in my apps root folder. I would love to know why re-import fixed this :)
Related videos on Youtube
joe_deniable
Updated on July 09, 2022Comments
-
joe_deniable almost 2 years
I'm trying the new Android Studio. I've exported a project from eclipse, using the build gradle option. I've then imported it in Android Studio. The R.java file under gen has a j in a little red circle on it. And in my source files, I get "cannot resolve symbol R" wherever I have a reference to a resource, e.g. "R.layout.account_list" etc.
I have never used Intellij before. Would appreciate any help as there obviously aren't many answer yet about Android Studio. Thanks!
-
Blackbelt almost 11 yearsClick on Build -> MAke Project
-
joe_deniable almost 11 yearsI had tried that but got an error saying "The specified gradle installation is not supported by this tooling API version". The gradle version being used, which I had to specify when importing the project, is in the "plugins" folder of the Android Studio installation folder. (It's version 1.6). Another issue is that when I quit and restart Android Studio, and it reopens the imported project, it says "The modules below have been removed from the gradle structure", and lists my main module (the name of my app).
-
joe_deniable almost 11 yearsI've tried using gradle 1.5 and it gets a bit further but still fails with this error: java.lang.ClassNotFoundException: org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
-
ADK almost 11 yearsMaybe you should to use Build -> Rebuild project
-
joe_deniable almost 11 yearsThanks, but that still causes the same errors. With gradle 1.6 the error is that the Gradle installation is not supported, with gradle 1.5 and 1.4 I get the classnotfoundexception. Maybe I'll try 1.3...
-
Benoit Duffez almost 11 yearsPlease, star this issue if you stumbled upon this from the upgrade of Android Studio from 0.1.5 to 0.1.6
-
-
joe_deniable almost 11 yearsThank you very much, that has fixed the R not resolved problem. I will maybe ask another question about the gradle issues.
-
Cartesian Theater almost 11 yearsIs there a way to do this manually? After upgrading I got the message "We will provide a UI to configure project settings later. Until then, please manually edit your build.gradle file(s.)" Also, for Mac it's command semicolon instead of F4.
-
takecare almost 11 yearsThis didn't do it for me (these folders are not present). I have the same problem, but the project was created from scratch in Android Studio, and it stopped working for no reason.
-
Moberg almost 11 yearsWhat do you mean by "Scheck SDKs on left"? Also, where can I find the gen and src folder?
-
Matt Clark almost 11 yearsPlease do not post
Me-Too
responses as answers. -
Ilya Kogan almost 11 yearsActually this was very helpful, as the "We will provide a UI later" message scared me off, and I almost gave up until I read Tim's answer.
-
Ilya Kogan almost 11 yearsAs Tim said, don't get scared by the "We will provide a UI to configure project settings later" message. This solution still works in Android Studio 1.7.0.
-
Andrew Barber almost 11 yearsWhen you copy content from somewhere else, please be sure to indicate where it came from. I've added that for you here.
-
speedynomads almost 11 yearsWhen I go to Modules > Sources, I can see a gen folder but not a src folder. When I run 'Rebuild Project' my project compiles fine. Any ideas?
-
UmAnusorn over 10 yearsI can see a src folder but not a gen folder. What should I do?
-
HBG over 10 yearsSorry to sound overly pedantic but those instructions are quite difficult to follow. What does F4 'into' Project Structure mean? You've said to check SDKs on the left but there's no checkbox. Under modules there is a 'Sources' tab and nowhere to 'check' gen and src and sources. Please elaborate.
-
Crossle Song over 10 years@Horace you can into Project Structure from File menu. you can check gen or src use right key menu.
-
alicanbatur almost 10 yearsThere is nothing like SDKs on the left.
-
Axoren almost 10 yearsThis answer is no longer relevant due to the time difference. It's over a year old and the menus have changed.
-
Crossle Song almost 10 years@Axoren Yes, Android Studio 0.6.1 now.
-
Fabian Fagerholm over 9 yearsCould you give some more detail? For example, how to identify which library is the extra one.
-
alap over 9 yearsWhat did you do in the Mac/Windows case?
-
Eliasz Kubala about 9 yearsHey bro! It's help me. Thanks ;)
-
Codebeat almost 9 yearsThis is wrong because you cannot access R.layout.<your app layout> . Import com.app.<projectname>.R instead (path can be different for your project).
-
Riot Goes Woof over 8 yearsOdd that "Make Project" doesn't do what this does. Just another voodoo magic operation that works because "it works".
-
GaryAmundson over 7 yearsAlmost 2 hours of beating my head on my desk over this... so thanks! But why doesn't a Clean or a Build solve this??? aargh.