Build against downloaded prebuilt GKI

WARNING: Building against downloaded prebuilts is currently experimental. If you encounter any errors, see common errors.

Step 1: Replace reference to GKI targets with downloaded targets

Replace all references to //common:kernel_aarch64 with //common:kernel_aarch64_download_or_build.

Replace all references to //common:kernel_aarch64_additional_artifacts with //common:kernel_aarch64_additional_artifacts_download_or_build.

In particular, look out for these places:

  • kernel_build(): base_kernel
  • Any target: kernel_build
  • copy_to_dist_dir: data
  • kernel_build_abi_dist: data

See Pixel 2021 mainline for an example (search for //common:kernel_aarch64):

https://android.googlesource.com/kernel/google-modules/raviole-device/+/refs/heads/android-gs-raviole-mainline/BUILD.bazel

Step 2: Build with --use_prebuilt_gki=<BUILD_ID>

In the build command, specify --use_prebuilt_gki=<BUILD_ID> to build against downloaded prebuilts.

For android13, the build ID must have a build target named kernel_kleaf.

Starting from android14 (including android-mainline), the build ID must have a build target named kernel_aarch64 with artifacts built with Kleaf. A build number >= 9359436 will work.

It is recommended to select the latest build ID from the branch.

Sample branches:

Other unspecified branches with a build target named kernel_aarch64 may also work if it is built with Kleaf. You may check whether a build is built with Kleaf by checking the build command in logs/build.log or the existence of a file with suffix _modules, e.g. kernel_aarch64_modules.

Sample command to build raviole-android13-5.15 against prebuilts from android13-5.15:

# On raviole-5.15 branch, build against prebuilts from android13-5.15.
# Build with --use_prebuilt_gki=<build_ID>. Example:
$ tools/bazel run --use_prebuilt_gki=8728678 //gs/google-modules/soc-modules:slider_dist

Common errors

You may see an error about failing to download a file because it does not exist (“404 Not Found”). For example:

ERROR: An error occurred during the fetch of repository '<filename>':
   Traceback (most recent call last):
        File "/mnt/sdc/android/raviole-mainline/build/kernel/kleaf/download_repo.bzl", line 128, column 48, in _download_artifact_repo_impl
                download_info = repository_ctx.download(
Error in download: java.io.IOException: Error downloading [<url>] to <path>: GET returned 404 Not Found

To resolve this, try using the latest build ID from the branch.

If you are still unable to resolve the issue, you may: