Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA 14 - Package R does not exist

Well, I recognize that this has been asked before, but in browsing the other answers:
IntelliJ IDEA - Can't build anything, always get "package R does not exist"
Error: java: package R does not exist
etc.
none of the solutions work.

This is for a project that was building fine until at least the last couple days, so whatever is causing the problem must be new.

Symptoms:
Attempting to to a Build > Rebuild Project fails. I see the step for compiling generates sources go by in the status bar, but the next compilation step fails with the dreaded "java: package R does not exist."

R is found just fine in the IDE, so only compilation fails, suggesting there is a problem with the compilation of the generated sources. This seems borne out by the fact that in the out/production/[module] directory, only some resource files show up, no compiled classes, nothing in the "generated" sbupackage, a no apk file.

Interestingly, when I connect my phone to the computer and try running the application on the device, new changes are picked up, so something is being successfully built somewhere.

Things I've tried:
Per the other threads I've tried:

  1. Doing a full rebuild.
  2. Restarting IntelliJ (including with invalidating caches)
  3. Restarting the computer.
  4. Checking that the gen package is included under sources.
  5. Checking for any Excludes (there are none)
  6. Deleting the stub R file and forcing IntelliJ to regenerate it (which it does promptly)
  7. Confirming that there is an Android facet on the module.
  8. Double-checking that the manifest xml file has not changed and that the referenced activity is correct.
  9. Checked that exclude output path is not checked (it's greyed as I'm inheriting from the project compile path, but I tried switching and manually unchecking it... no luck).

The only recent changes in xml were:

  • A new item in a menu file. I tried removing it to see if somehow that was an issue even though there were no errors reported, but the problem persisted.
  • I moved a View class to a subpackage of its prior package. That View class is referenced once in a layout xml and I confirmed that the xml was updated with the new package name.

So at this point I'm out of ideas. Sorry to rehash a somewhat common question.

like image 899
Ben Leitner Avatar asked Jan 31 '15 04:01

Ben Leitner


3 Answers

I have the same problem and it definitely related to last update of the IDE. My version is IU-139.1117.1 Before the update Build -> 'Rebuild Project' was working ok in a windows and a mac installation of the IDE. I updated windows first and 'Rebuild Project' shows the error 'Package R does not exist' even for a new Android project. Same error apeared in mac installation imediately after the update. 'Make project', 'Make module' and 'Compile' commands on the Build menu are all working ok with no error only 'Rebuild project' raises the error. For a new Gradle Android project everything works ok. It seems something is wrong with last update.

like image 172
Panagiotis Piperopoulos Avatar answered Nov 02 '22 15:11

Panagiotis Piperopoulos


It is reported issue in IDEA 14.0.3 (http://youtrack.jetbrains.com/issue/IDEA-135234).

You can try to Compile Module (Ctrl-Shift-F9) for the module that contains missing R file. It works for me (but I have to do this every time i add/remove items in resources).

like image 29
Vladimir Petrakovich Avatar answered Nov 02 '22 16:11

Vladimir Petrakovich


don't use Rebuild Project, use Make Project and refresh your project,maybe you should try it a few more times.

like image 4
qqli Avatar answered Nov 02 '22 15:11

qqli