name: Build Android 14 GKI Kernels on: workflow_call: # This allows this workflow to be called from another workflow jobs: build-kernel-a14-kernelsu-susfs: runs-on: ubuntu-22.04 timeout-minutes: 2160 # Set maximum timeout steps: - name: Maximize build space uses: easimon/maximize-build-space@master with: root-reserve-mb: 8192 temp-reserve-mb: 2048 remove-dotnet: 'true' remove-android: 'true' remove-haskell: 'true' remove-codeql: 'true' - name: Download prebuilt toolchain run: | AOSP_MIRROR=https://android.googlesource.com BRANCH=main-kernel-build-2024 git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV - name: Set boot sign key env: BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} run: | if [ ! -z "$BOOT_SIGN_KEY" ]; then echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV else echo "BOOT_SIGN_KEY is not set. Exiting..." exit 1 fi - name: Install Dependencies run: | # Install dependencies sudo apt update sudo apt install -y lz4 gzip repo perl - name: Build for all configurations run: | BUILD_CONFIGS=( "android14-5.15-131-2023-11" "android14-5.15-137-2024-01" "android14-5.15-144-2024-03" "android14-5.15-148-2024-05" "android14-5.15-149-2024-06" "android14-5.15-153-2024-07" "android14-5.15-158-2024-08" "android14-5.15-167-2024-11" "android14-5.15-X-lts" "android14-6.1-25-2023-10" "android14-6.1-43-2023-11" "android14-6.1-57-2024-01" "android14-6.1-68-2024-03" "android14-6.1-75-2024-05" "android14-6.1-78-2024-06" "android14-6.1-84-2024-07" "android14-6.1-90-2024-08" "android14-6.1-112-2024-11" "android14-6.1-115-2024-12" "android14-6.1-X-lts" ) for CONFIG in "${BUILD_CONFIGS[@]}"; do CONFIG_DETAILS=${CONFIG} # Create directory and proceed with your steps echo "Creating folder for configuration: $CONFIG..." mkdir -p "$CONFIG" cd "$CONFIG" IFS="-" read -r ANDROID_VERSION KERNEL_VERSION SUB_LEVEL DATE <<< "$CONFIG_DETAILS" FORMATTED_BRANCH="${ANDROID_VERSION}-${KERNEL_VERSION}-${DATE}" # Git clone echo "Cloning AnyKernel3 and other dependencies..." git clone https://github.com/TheWildJames/AnyKernel3.git -b "${ANDROID_VERSION}-${KERNEL_VERSION}" git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "gki-${ANDROID_VERSION}-${KERNEL_VERSION}" git clone https://github.com/TheWildJames/kernel_patches.git echo "Creating folder for configuration: $CONFIG..." mkdir -p "$CONFIG" cd "$CONFIG" # Initialize and sync kernel source echo "Initializing and syncing kernel source..." repo init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16 REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH}) DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml # Check if branch is deprecated if grep -q deprecated <<< $REMOTE_BRANCH; then echo "Found deprecated branch: $FORMATTED_BRANCH" sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH fi # Sync repo and apply patches repo --version repo --trace sync -c -j$(nproc --all) --no-tags --fail-fast # Add KernelSU, SUSFS patches, and build the kernel echo "Adding KernelSU..." curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash - #cd ./KernelSU-Next/kernel #sed -i 's/ccflags-y += -DKSU_VERSION=16/ccflags-y += -DKSU_VERSION=12000/' ./Makefile #cd ../../ echo "Applying SUSFS patches..." cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./KernelSU-Next/ cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch ./common/ cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/ cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/ # Apply patches cd ./KernelSU-Next patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true cd ../common patch -p1 < 50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch || true cp ../../kernel_patches/69_hide_stuff.patch ./ patch -p1 -F 3 < 69_hide_stuff.patch cd .. cp ../kernel_patches/apk_sign.c_fix.patch ./ patch -p1 -F 3 < apk_sign.c_fix.patch cp ../kernel_patches/core_hook.c_fix.patch ./ patch -p1 --fuzz=3 < ./core_hook.c_fix.patch cp ../kernel_patches/selinux.c_fix.patch ./ patch -p1 -F 3 < selinux.c_fix.patch # Add configuration settings for SUSFS echo "Adding configuration settings to gki_defconfig..." echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig # Build the kernel using Bazel echo "Building kernel..." sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./common/scripts/setlocalversion sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl sed -i '2s/check_defconfig//' ./common/build.config.gki perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT Sat Apr 20 04:20:00 UTC 2024"}' ./common/scripts/mkcompile_h rm -rf ./common/android/abi_gki_protected_exports_aarch64 rm -rf ./common/android/abi_gki_protected_exports_x86_64 tools/bazel build --config=fast --lto=thin //common:kernel_aarch64_dist # Create boot images echo "Creating boot images..." mkdir -p bootimgs cp ./bazel-bin/common/kernel_aarch64/Image ./bootimgs cp ./bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs cp ./bazel-bin/common/kernel_aarch64/Image ../ cp ./bazel-bin/common/kernel_aarch64/Image.lz4 ../ gzip -n -k -f -9 ../Image >../Image.gz cd ./bootimgs echo 'Building Image.gz' gzip -n -k -f -9 Image >Image.gz $MKBOOTIMG --header_version 4 --kernel Image --output boot.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot.img $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot-gz.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-gz.img $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot-lz4.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-lz4.img cd .. # Create AnyKernel3 ZIP files echo "Creating AnyKernel3 ZIP files..." cd ../AnyKernel3 # Creating ZIPs for kernel images ZIP_NAME="AnyKernel3-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" mv ../Image ./Image zip -r "../../$ZIP_NAME" ./* rm ./Image ZIP_NAME="AnyKernel3-lz4-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" mv ../Image.lz4 ./Image.lz4 zip -r "../../$ZIP_NAME" ./* rm ./Image.lz4 ZIP_NAME="AnyKernel3-gz-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" mv ../Image.gz ./Image.gz zip -r "../../$ZIP_NAME" ./* rm ./Image.gz # Go back to the original directory cd ../../ # Delete the $CONFIG folder after building echo "Deleting $CONFIG folder..." rm -rf "$CONFIG" done - name: Upload build artifacts uses: actions/upload-artifact@v4 with: name: kernel-artifacts-a14 path: | *.zip *.img