7

While building Android source code I am getting this error:

out/target/common/obj/APPS/SystemUI_intermediates/src/com/android/systemui/R.java:10: duplicate class: com.android.systemui.R

Even if I execute the rm command to remove that file or execute make clean. Why is that, and how do I deal with it?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Sandy
  • 71
  • 1
  • 1
  • 3

6 Answers6

9

You probably have 2 R.java files in 2 different directories. You should run a search to locate and delete both of them, then try to rebuild.

3

One build system can leave generated R.java source file in one directory, while other build system will take it as a regular source file and put generated R.java into another directory.

For example, you can use AOSP building process, but after opening your sources in IntelliJ it breaks, because IntelliJ has put extra R.java under gen/ directory.

Summary: properly clean your output directory and check that your source directories doesn't get extra R.java file. run find . -name R.java in project root directory to see if any reduntant R.java files like in gen dir

Xiao
  • 12,235
  • 2
  • 29
  • 36
beefeather
  • 1,040
  • 5
  • 8
2

It did not help me deleting the duplicated R.java and BuildConfig files because it was always recreating it and showing the above error.

What helped me is understanding why the files where duplicated at the first places. In my case it was because I mistakenly made a loop dependency between my modules in the project. This way when compiler started creating classes for one of the modules it already compiled as a dependency it showed the error. Removing the unneeded dependency and recompiling the project fixed the problem.

P.S.
The reason I did not find the dependency problem right away is because the Android studio I am currently using (0.6.1) has a bug where sometimes the project settings view gets buggy and shows modules that were already removed or does not show modules that are currently there in the dependency list. Restarting the Android studio fixes the problem, so I suggest restarting before applying the above fix.

MikeL
  • 5,385
  • 42
  • 41
  • You're absolutely right. You can remove the build files until your face is blue, but they will always regenerate/rebuild each time causing a duplicate R.java conflict. – Herb Meehan Sep 14 '15 at 00:22
0

I got the same error while deploying Android application from QT. I've opened the build directory like
"C:\Myproject\src\builds\build-helloworldandroid-Android_for_armeabi_v7a_Clang_Qt_5_12_3_for_Android_ARMv7-Release"
and I deleted all of the files and compiled again. Errors disappeared and successfully ran the application.

astarakastara
  • 475
  • 5
  • 17
0

If you tried deleting your project files and directories in the past, you probably did not delete the classes that gave you duplicate class errors, albeit unintentionally.

Build > Clean Project fixed this issue for me.

rmutalik
  • 1,925
  • 3
  • 16
  • 20
0

check whether you have change package name in the manifest file or try to delete the R.java file and then build it again.

deepa
  • 2,496
  • 1
  • 26
  • 43