简体   繁体   中英

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.

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.

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

不要使用Rebuild Project,使用Make Project并刷新你的项目,也许你应该多试几次。

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

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.

解决了智能IDEA的14.1更新,现已上市。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM