[android] Android Studio don't generate R.java for my import project

I import a project to Android Studio , but the R.java is always empty.

public final class R {
}

I have tried:

  1. Make project,make module, remake, etc.
  2. Project Setting-modules-sources, then add src and gen as my source folder.

But they are not take effect.

This question is related to android android-studio

The answer is


I had a lot of problems exporting a project from Eclipse (assuming that is where you are exporting from). It was much easier for me to create a new project in Android Studio, then copy over the java files, xml files, layout directories, etc, and the AndroidManifest, into the appropriate location in the new project.

If you already have an R.java file for your project, you could try just copying it over to the new project. In Android Studio the R.java file seems to reside in build/source/r/debug/your-package-name/


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.


Had the same problem and solved it by:

  1. running / building the project (it was deployed to the device, in my case)
  2. right-clicking on the Project/Module/build folder
  3. choose: Synchronize 'build' - then i found

Project/Module/build/source/r/debug/package/R.java

Probably it was even there before the project was build, but I didn't test that.

I hope this was helpful, even though the answer comes a bit late and by now the bug with the

Settings->Compiler->[ ] Use external build

should be fixed afaik ;-)


I had a similar problem within my project using Android Studio 1.5.1. For me, bulding the project from command line by using following command resolved the problem:

gradle assembleRelease

I managed to regenerate R: File->Settings->Compiler

then UNCHECK "Use in-process build"

Rebuild Project


Go to Menu-Tab -> Project -> Build -> Automatically(check this option). and than reopen a new project.


I had a similar problem in a large multi-module project with many dependencies among the modules. What worked for me, was to attempt to build separately from command line all the modules that failed to build within Android Studio. That gave me indications on resources missing in each project. From the project level in my console I did:

$ cd moduleName
$ ../gradlew assembleDebug

This provided me with a number of 'No resource found that matches the given name' errors, that weren't shown before, when I build the project as a whole.


File->Invalide Cahces / Restart

I found my solution here. In short make sure not only the Eclipse plugin(if you are using eclipse) is updated. Also ensure that the Android SDK Tools, the SDK platform-tools and the SDK Build-tools are updated. After this restart your machine.


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 .


Best Solution for android studio Users :

Goto : Menu tab - > Build - > Rebuild Project

after rebuild Proj. your R.Java file problem will be solve automatically ..


I failed even if I tried to update the SDK tools as mentioned here.

Here is how I solved the problem (for the library projects imported).

In File -> Project Structure -> Modules, I removed the problematic projects, and added them again by selecting New Module -> Android Library Module.

Select "Android Library Module" when adding project.

After rebuilding the project, I got all the R.java files back.


When I was trying to add another flavour I face same situation.

I found in one of post and I gave successful try and it work. Following I did: File -> Invalidate Cached/Restart.


As for me, the problem was in this superfluous line:

import android.R;


Did you follow steps here? First update your Eclipse ADT plugin, then export project and the import in Android Studio.

http://developer.android.com/sdk/installing/migrate.html


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.


Check your project package! I had brought some classes over from another project and did not notice the subtle change in the package name. See top of your AndroidManifest.xml


I will answer the question even though it has been a long time since it was thrown, just in case someone else get to it.

Tested on Android Studio ONLY (but I guess it could work for Eclipse as well) :

Check your build/source/r folder. In there, you should find some directories labelled under the name of your gradle build name (default : debug). Verify that the name of the package associated with R is the one you want.

I know this trick solves the problem of switching namespace, because Android Studio (or Gradle I don't know who is responsible for that) seems not to regenerate it in that case.

I haven't tried it when importing a project from Eclipse though.


So, this is the latest solution if anyone get's stuck like I did today especially, for R.Java file.

If you have lost the count of:

  • Clean Project
  • Rebuild Project
  • Invalidate Caches / Restart
  • deleted .gradle folder
  • deleted .idea folder
  • deleted app/build/generated folder
  • checked your xml files
  • checked your drawables and strings

then try this:

check your classpath dependency in your Project Gradle Scripts and if it's, this:

classpath 'com.android.tools.build:gradle:3.3.2'

then downgrade it to, this:

classpath 'com.android.tools.build:gradle:3.2.1'

I had this problem after update gradle...

There are several reasons that causes the projectenter image description here not to be built:

1-Unknown error in drawable or xml files

2-Update gradle or libraries and etc ...

Solution :

1-Clean and rebuild project

2-Delete .idea and build folders in project file(shown in picture) then goto "File/Invalidate catch-restart"

3-Roll back to previous gradle version and libraries.


Just use the 'Rebuild Project' from the 'Build' menu from the top menu bar.


Go to File ? Settings ? Editor ? Auto Import and at java tab you should have:

Insert imports on paste: ASK.
If you have import for ALL, then Android Studio import other file.