Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 605
migea Avatar asked Apr 25 '15 20:04

migea


People also ask

How is the r file generated in Android Studio?

Android R. java is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory. If you create any component in the activity_main. xml file, id for the corresponding component is automatically created in this file.

Where can I find R Java files?

Change the view of your project from Android to Package mode. Then Open app folder then build, then generated folder, then source folder and then you will find r folder, then you will find your package name, click on that folder you will find R. java file there.

What's the role of the R Java file that is automatically generated by the Android SDK?

What is the role of the R. java file in an Android application project? A. It contains all resource IDs allowing the developer to reference them from the code using integers.


Video Answer


1 Answers

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.

like image 173
hichris123 Avatar answered Nov 08 '22 18:11

hichris123