7

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?

hichris123
  • 9,735
  • 15
  • 51
  • 66
migea
  • 467
  • 4
  • 9
  • 23
  • 2
    When the project is built the R file is generated. I'd suggest a Build -> Rebuild Project – Brad Brown Apr 25 '15 at 20:29
  • 2
    I did your you've suggested but it doesn't generate the R file. Are you sure that it must be generated? Or I must perform this task near after I'd created the project? – migea Apr 25 '15 at 20:31
  • Yes, it's generated. If you look in project/app/build/generated/source/r/ it should be listed in there. – Brad Brown Apr 25 '15 at 20:36
  • 1
    It isn't and I don't know why. In the location you've mentioned is only a folder 'debug' which is also empty: http://i.imgur.com/2iRnNBK.png – migea Apr 25 '15 at 20:39

1 Answers1

7

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.

Community
  • 1
  • 1
hichris123
  • 9,735
  • 15
  • 51
  • 66
  • 1
    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.. – migea Apr 25 '15 at 20:32
  • Does the project build, @migea? If so, you don't need to worry about it -- it's there. – hichris123 Apr 25 '15 at 20:34
  • 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: http://i.imgur.com/sTldGAC.png – migea Apr 25 '15 at 20:42
  • 2
    @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. – hichris123 Apr 25 '15 at 20:46
  • 1
    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: http://i.imgur.com/InBHkLb.png – migea Apr 25 '15 at 20:50
  • 1
    I've succeeded finally. Now it has suggested me to import that files and it works fine. Thanks for your support – migea Apr 25 '15 at 20:53
  • Happy to help, @migea. :) – hichris123 Apr 25 '15 at 21:02
  • 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 :( – CandleCoder Jan 06 '16 at 14:45