Build faild randomly caused by resouce copy race condition during apk buiding

77 views
Skip to first unread message

raymond....@gmail.com

unread,
Jul 20, 2021, 10:42:10 AM7/20/21
to Android Building
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

Dan Willemsen

unread,
Jul 20, 2021, 10:58:21 AM7/20/21
to android-...@googlegroups.com
One fix for this is to move over to using an Android.bp to build your app rather than an Android.mk 🙂

But I also submitted a fix for this into aosp/master last week: https://android-review.googlesource.com/c/platform/build/+/1764131

- Dan

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-building/5f6a6033-6620-40ae-a3dd-125c35f6b394n%40googlegroups.com.

raymond....@gmail.com

unread,
Jul 29, 2021, 11:35:44 AM7/29/21
to Android Building
Thanks Dan

The CL is useful.

Reply all
Reply to author
Forward
0 new messages