Hi ,
Our Android 11 build has been failing randomly with the following error:
> cp: cannot create regular file 'out/target/common/R/androidx/vectordrawable/R.java': > File exists
then, We found the reason for the compilation failure in build/make/core/
definitions.mk:
define find-generated-R.java
$(hide) for GENERATED_MANIFEST_FILE in `find $(1) \
-name Manifest.java 2> /dev/null`; do \
dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \
mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
cp $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
done;
$(hide) for GENERATED_R_FILE in `find $(1) \
-name R.java 2> /dev/null`; do \
dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \
mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
cp $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
|| exit 31; \
cp $$GENERATED_R_FILE $(2) || exit 32; \
done;
@# Ensure that the target file is always created, i.e. also in case we did not
@# enter the GENERATED_R_FILE-loop above. This avoids unnecessary rebuilding.
$(hide) touch $(2)
endef
When two or more unrelated modules depend on a module that needs to be compiled 编by appt2, multiple files with the same name will be copied to the same directory.
When the compilation time of these modules overlaps, the copy operation conflicts, which leads to the failure of the build
We also check the aosp master, it may has the same issue
B/R
Raymond