开发者

Android source build: duplicate class

开发者 https://www.devze.com 2023-03-22 21:14 出处:网络
While bui开发者_Python百科lding 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.system

While bui开发者_Python百科lding 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?


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.


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


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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消