I'm trying to use IntelliJ IDEA to work on an Android app with a colleague that swears by it, but I'm unable to build any of the Android projects he sends me because whenever I try a build I get an error saying package R does not exist
.
I have been trying out everything I can think of. Examples and other things to note are:
Making sure I have a version of the
local.properties
file pointing to the root of my Android SDKs folder.Fiddling with various settings in the project structure dialog (I won't list them all).
The project I'm working on has two library projects with also use the
R
class and they work fine.The intellisense within the IDE recognises the
R
class and comes up with the stuff I expect.
Any help would be greatly appreciated. I feel I'm missing something basic.
Try create new project and select "Create project from existing sources"
Another possible solution to those listed here is to check that the package name in your AndroidManifest.xml matches that of your actual package:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.yourpackagename" >
My package was building fine until I refactored the package name, everything refactored except for the package name in manifest file (see above) which caused the error "Package R does not exist".
In my case, I added some classes from another project and I had to add the import to the R package from my actual project:
I've refactored the packagename and intellij didn't update it in the manifest.
So if you've refactored the packagename then go to the manifest and update the attribute "package" in the root of the xml file save and rebuild it. If any errors occur then it's probably a wrong packagename in the import (at least this was my case) so just fix them
hope this helps anyone
If you run into this with a package that has been building before you need to "Rebuild". Build->Rebuild Project . Deleting gen does not do it since IDEA saves the actual generated R somewhere else.
I've started playing around with IntelliJ since I've had issues with the new Android Studio and wanted to try something that was a little more stable (I've never really used either before). I ended up getting the dreaded “package R does not exist” error. In my experience, this is usually something messed up in an XML file. For me, the problem was actually with the AndroidManifest.xml file for an Android Library Module that I had created for ActionBarSherlock. For whatever reason, when it created the AndroidManifest.xml file it didn't bother to use the AndroidManifest.xml file that came with ABS and it put the following in:
When I created this Module I chose File > New Module... I then Selected Library Module under the Android section and for the Content Root I browsed to the location of the files for ABS (Other fields auto filled in correctly and I didn't change them). I then clicked finish and it prompted me if I wanted to keep the local file or the memory file for project.properties. I chose to keep the local file and it didn't prompt me for any others after that.
I have no idea why it messed up the AndroidManifest.xml file (maybe what I did above was wrong...???), but to fix it I just copied the original AndroidManifest.xml that I had downloaded with the library and replaced the messed up AndroidManifest.xml file. After that I did Build > Rebuild Project and it resolved the “package R does not exist” errors.
One other thought, @xbakesx mentions the Facets settings, and for any modules you are using as libraries, you should make sure that "Library module" is checked under Facets for that Module. I had some issues with that at first when I was trying to figure out how to configure libraries in IntelliJ/Android Studio (I've really only used Eclipse).