From this tutorial.
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.
This id can be used in the activity source file to perform any action
on the component.
Hence you should not worry about the R.java
file, as this will be generated automatically when you will build the project. The R.java
might not be generated in some cases though, mostly if there is an error in your layout files. Check your layout files and look for errors in there. Fix the error and you should be able to get the reference of the R.java
file in your activity.
To import the R.java
file in your activity, use the automatic import option. In most cases, Alt + Enter
does the trick for you for automatic import.
If you are still having trouble finding the R.java
, you might consider invalidating the cache of the Android Studio from File -> Invalidate Caches/Restart
.

Hope that helps!