How to avoid Android Kernel from always rebuilding from scratch?
02:01 13 Jul 2026

Every time that I need to build a specific Android Kernel, it restarts the whole build from scratch, ignoring absolutely all previously built objects. In other words, it doesn't matter if I had touched or not any file in the source tree or even if I have successfully built the Kernel before.

The "problematic" Kernel is this one:

  • It's based on the official daisy (Xiaomi Mi A2 Lite) Kernel for Android 8.1

  • The Kernel version is 3.18.71

  • The ROM where this Kernel runs is the stock

  • Since the Kernel above was modified by me, you can find the official untouched one here (and there's also a mirror of it in a branch called daisy-o-oss at the same daisy_kernel repo)

  • The expected behavior should be make to skip everything that was already built while their source files keeps unchanged

  • make doesn't show any errors

  • I've tried to use ccache, but make also ignored the cached objects

  • Despite it's been 1-year now, I remember that even newer daisy Kernels (from Android 9, 10 and unofficial 11) also suffer from this same same hazard

The used LLM pointed three possible reasons for this issue:

  1. include/generated/bounds.h and include/generated/asm-offsets.h being regenerated by the root Kbuild. This seems to be fixed when I added an "integrity test" to both cmd_bounds present in the file, like this:

    define cmd_bounds
            (set -e; \
             ...
             echo "#endif" ) > $@.tmp; \
             if [ -r $@ ] && cmp -s $@ $@.tmp; then rm -f $@.tmp; else mv -f $@.tmp $@; fi # this line
    endef
    
  2. FORCE dependency of .PHONY target (files Makefile and scripts/Makefile.build), but it seems to be skipped when I run the build

  3. Some unknown dependency of toolchain error triggering the rebuild of init/main.o. This one seems to be the closest candidate, but I still was unable to figure out what may be calling it

android linux build kernel xiaomi