Hi everyone,
since I've spent many many days on this I wanted to let you know so you don't have to.
Short version:
"make -j24 otapackage" cause random build errors
Longer version:
The otapackage generation for Lollipop (might also be applicable for M?) will start multiple "make" processes to build an otapackage for each dtb-file (device tree blob). Since there is no dependency on the "otapackage" target, running with the make jobserver enabled (i.e. make -j) this will start multiple builds at the same time causing random build errors (corrupt zip/apk-files etc...).
A simple solution to this is to add a dependency on the built files for otapackage.
Example:
In build/core/Makefile:1690
.PHONY: otapackage
-otapackage:
+otapackage: $(BUILT_TARGET_FILES_PACKAGE) $(DISTTOOLS)
Thank you for posting this information!