开发者

What's the easiest way to force Idea to generate the R.Java file?

I am trying to run Android sample applications using intellij idea and R.Java fil开发者_开发技巧e is missing form notepad samples source directory.


Make sure you have the right settings: project structure -> Facets -> Android -> yourproject -> compiler

Check compile resources by IDE and Regenerate R.java when resources are changed.

This stole most of my morning, hopefully I'll save someone else some time:)


Make sure you have a gen folder in your project root. If you don't, make one yourself.


Use Build | Make. Actually, IDEA generates R.java file automatically every time you make a change in any XML file under the /res directory.

UPDATE: /gen directory must be present in the project and also configured as a Source root in IDEA module so that it can resolve the IDs in your source code.


Build -> Compile 'R.java'

or simply Ctrl+Shift+F9.


Pay attention that, in current version of IDEA 12, the by-design behaviour is not to generate R.java in the generated sources project directory, but in an IDEA's system directory:

http://youtrack.jetbrains.com/issue/IDEA-99045

"It is behaviour of IDEA 12, it doesn't generate full R.java in gen folder, it generates it in the IDEA's system dir during compilation."

They intend to change this confusing behaviour, but if you're currently working in IDEA 12, look into ~/.IntelliJIdea12\system\compiler\YOUR_PROJECT_NAME.RANDOM_STRING\.generated\aapt\YOUR_PROJECT_NAME.RANDOM_STRING\production\package\R.java for the actual generated source file.


Fix all errors appear on .xml files. R.java will be re-appeared


Also make sure to check your imports. Sometimes when your IDE (eclipse & intellij as well) cannot find your generated R class and auto-imports android.R.

import android.R kills everything you are doing in your generated sources!

Cost me 30min of my life...


In AndroidStudio use: Build -> Rebuild Project.

And remember, the generated R file is not in the project "gen" directory. It is in the "out" directory (drill down to your project).


If you are using IDEA 12 on Windows 7 (and probably Vista and 8), R.Java can be found at :

C:\Users\[username]\.IdeaIC12\system\compiler\[project].nnnnnnnn\.generated\aapt\[project].nnnnnnnn\production\[your\name\space]\R.java 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜