Is there a way to generate the R.java file in Android Studio?

17,545

R.java is quite different in Android Studio than it is in Eclipse. Since you say this is an old project, I'm assuming that it was originally from Eclipse. In Eclipse, R.java is included in the source tree. However, in Android Studio, it is hidden away. From another Stack Overflow answer:

1. build

This has all the complete output of the make process i.e. classes.dex, compiled classes and resources, etc.

In the Android Studio GUI, only a few folders are shown. The important part is that your R.java is found here under build/source/<flavor>/r/<build type(optional)>/<package>/R.java

You shouldn't need to manually interact with R.java at all. It can be re-generated from the source code. Thus, it is likely that you won't have any problems -- R.java will be auto-generated and all will be well. If it isn't, try a rebuild of the project.

Share:
17,545
migea
Author by

migea

asking question here

Updated on June 14, 2022

Comments

  • migea
    migea about 2 years

    I have a saved Android project from long time ago and now I must to work on it.

    I've created a New Project in Android Studio and I've imported all the Java and XML files inside it but the R.java file is missing.

    I guess that it didn't save the original. Can I recover it somehow or generate it?

  • migea
    migea about 9 years
    Nope, the original was from Android Studio too, and it isn't that old... about 7-8 months. I've rebuilt the project and nothing appeared..
  • hichris123
    hichris123 about 9 years
    Does the project build, @migea? If so, you don't need to worry about it -- it's there.
  • migea
    migea about 9 years
    I don't but in the original project it was so, and there are calls from it in the project's classses as it can be seen here: i.imgur.com/sTldGAC.png
  • hichris123
    hichris123 about 9 years
    @migea That's normal, but you don't need to import my_package_name.R. It resolves automatically -- if you remove the import statement, it should fix your build errors & cause R.java to be generated.
  • migea
    migea about 9 years
    Well, I've commented the imported R files and after that I've rebuilt the project. It still doesn't work. This is what I get: i.imgur.com/InBHkLb.png
  • migea
    migea about 9 years
    I've succeeded finally. Now it has suggested me to import that files and it works fine. Thanks for your support
  • hichris123
    hichris123 about 9 years
    Happy to help, @migea. :)
  • CandleCoder
    CandleCoder over 8 years
    Its not getting generated It says could not find symbol 'r', I rebuilt the project, cleaned the project, Restarted the eclipse ,Cleared the cached...Still no Luck :(