Android Studio does not recognize R.java
2024.3.9
2018.5.23
R.java may suddenly become unrecognizable, or newly added IDs may not be added by automatic update.
Location of R.java
R.java is a file that manages the resource IDs automatically generated by Android Studio and stored in ./app/build/generated/source/r/debug/URI
.
ID added to R.java is not reflected
When I added android:id="@+id/new_id"
in the XML layout file, it should have been added automatically until a few minutes ago, but suddenly it was not recognized anymore.
I saved the project, closed it, restarted Android Studio, and reopened it.
R.java itself is unrecognizable
There was also an incident in which R was highlighted in red when an ID was used as an argument in a java file because the existence of R.java itself could not be read.
It is said that removing the errors in the XML file and overwriting the file may fix the problem, but this did not work, so I ran [Build] > [Clean Project], which fixed the problem.