Ben Leitner
Ben Leitner

Reputation: 329

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:

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

Upvotes: 16

Views: 9914

Answers (7)

Peti
Peti

Reputation: 1700

I had the same issue on a Windows 7 box today with a Java 7 Gradle project, using IntelliJ 14.1.5.

The problem was that somehow the classpath was "too long", but IntelliJ gave me only those strange "java: package foo does not exist" compile error's.

The usual tricks (see also above) did not help.

The workaround was to shorten the classpath a bit, in my case setting GRADLE_USER_HOME to c:/.gradle (was before c:/users/myusername/.gradle). After resyncing the gradle project everything worked fine.

The problem was therefor obviously IMO some kind of windows filesystem path length restriction.

Upvotes: 0

Ulises Ponce Mendoza
Ulises Ponce Mendoza

Reputation: 123

Solved with the 14.1 update of intelliJ IDEA, available now.

Upvotes: 0

sandalone
sandalone

Reputation: 41759

If you cannot wait for a officially stable build, install IDEA EAP 14.0.4 (IntelliJ IDEA 14.0.4 EAP build 139.1408, released on February 20th, 2015) from https://confluence.jetbrains.com/display/IDEADEV/IDEA+14+EAP

I've just solved all issues and rebuild project works again.

Upvotes: 0

qqli
qqli

Reputation: 196

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

Upvotes: 4

Vladimir Petrakovich
Vladimir Petrakovich

Reputation: 4286

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).

Upvotes: 10

Mohamed Salemyan
Mohamed Salemyan

Reputation: 691

Try File | Invalidate Caches. This is solve my problem.

Upvotes: 0

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.

Upvotes: 11

Related Questions