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?

4
  • 2
    When the project is built the R file is generated. I'd suggest a Build -> Rebuild Project Commented Apr 25, 2015 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? Commented Apr 25, 2015 at 20:31
  • Yes, it's generated. If you look in project/app/build/generated/source/r/ it should be listed in there. Commented Apr 25, 2015 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: i.imgur.com/2iRnNBK.png Commented Apr 25, 2015 at 20:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

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..
Does the project build, @migea? If so, you don't need to worry about it -- it's there.
@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.
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
I've succeeded finally. Now it has suggested me to import that files and it works fine. Thanks for your support
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.