Home » Android » Android xml layout file is not being added to R.java

Android xml layout file is not being added to R.java

Posted by: admin May 14, 2020 Leave a comment

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"



This is my new layout file and it is not being detected by eclipse, nor is it in the R file. I can’t create any new layout files or perhaps I’m doing it all wrong. All my older layouts are seen fine.


Also, a layout I had created previously I have edited with a new ID, however that new id is not detected either.

How to&Answers:

Clean your project or restart the eclipse, i guess it’s the problem with eclipse automatic building.


Look to the imports, the R imported maybe is not correct.


I have this import

import android.R;

I’ve deleted this and layout is working again


If ANYTHING is wrong in your layouts, new updates aren’t added to the R file. Look at the errors panel, and possibly to a clean rebuild to see what errors are popping up.

Your layout xml is fine. The file itself may have an incompatible name.


I had the same issue. I took Eclipse’s advice and removed

import android.R;

And replaced all references to R with the fully qualified name [project-specific package].R since the R file was actually being generated under some package, and the default contained nothing of interest.

You can check the package name by looking in the gen folder.


My development environment: [ MacBook Pro, Eclipse: 4.4.0]

I’ve tried all of the above, but no sucess.

Its resolved in the following steps:

Step-1)Comment out import android.R;
Remove it complete.

Step-2) import packageName.R;


import com.arundhwaj.augmented_reality.R;

Hope it help someone.


Probably problem in a name xml a file. The name shouldn’t contain upper case symbols.


In my case the IDE (Eclipse) added the import android.R again and again. I had to update my Android SDK to make that go away.


I had the same problem and I solve it renaming the xml file with lowercase symbols.


I had this same problem and fixed it by adding



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


In my case I found out that when I’had just started the project I renamed the package but the refactory function didn’t canghe the name of the package of the generated code… so renaming that I corrected the missmatch.


This can be a auto build issue with eclipse. So even if you remove android.R and do clean-build the issue may not go away. And prevent any R.java files to be created in the gen folder

  1. Remove import android.R (The R referred should be you package R not the android.R)
  2. Make sure the project is error free for a successful build. You can comment out error throwing references to R in project (if on worst case comment all R references).
  3. Clean the Project

  4. This should remove all the stale references and do a fresh compilation. Once the R.java is generated. Uncomment all R references . Now the layout and other references which were not getting recognized previously should resolve


I changed
{ android:src=”@drawable/Myapp” } to
{ android:src=”@drawable/myapp” } in my layout.xml then I could select R.layout.mylayout in Mainactivity.java

Capital letters are not allowed.


If you are facing same issue Just “Clean” the Project it should work.


Instead of using android.R.layout. use

EXAMPLE, in arrayadapter **ArrayAdapter<E> item= new ArrayAdapter<>(this,R.layout.list_item,array); where E is the object** 


One more reason that this can happen. If for example you add a new module and you give it an existing package name, you’ll get duplicate BuildConfig.java class files built. The mergeDexRelease and mergeDexDebug gradle task won’t like that and fail with an error “Program type already present” followed by the name of the duplicate class.

If you didn’t notice the error, you’ll see things like R.id.yourLayout or R.drawable.yourIcon being undefined in your app. Ironically string resources can still be found. The correction is to change the package name in one of the modules with the duplicate name.

If you want to find the locations of the duplicate classes in Android Studio, use “Navigate/Class…” and enter the name of the duplicate class. You might need to check the “include non-project items”