I import a project to Android Studio , but the R.java is always empty.
public final class R {
}
I have tried:
Goto File -> Settings -> Compiler now check use external build
then rebuild project
I managed to regenerate R: File->Settings->Compiler
then UNCHECK "Use in-process build"
Rebuild Project
Just use the 'Rebuild Project' from the 'Build' menu from the top menu bar.
In my case I had an empty line prior a drawable definition in xml. This was braking aapt essentially not allowing to generate R.java .
For me the problem with the R class has been related to automatically organized imports.
As AndroidStudio has the option to allow the automatic imports, it took the wrong R class and thats why the ids have not been found and Gradle was throwing errors!
So check if the import to the R class is referencing to the one you need.
If you are facing this problem in a specific module in your project, you could try opening just that module as a project and then build it. This worked for me. It was failing to generate the R file for the module when I was trying to re-build the entire project.