安卓源码编译 grand 2025-12-27 2025-12-27 安卓源码编译 目标手机:pixel6
android版本:13
内核:5.10
平台:ubuntu22.04 32swap 500g硬盘
参考 Android Build系列专题【篇一:开发环境搭建】_android开发环境搭建-CSDN博客
构建 Android | Android Open Source Project
代号、标记和 build 号 | Android Open Source Project
Android13源码下载及全编译流程_android源码下载-CSDN博客
安卓分支选择 先去根据自己的机型选自对应的分支
选择驱动
换源 1 sudo code /etc/apt/sources.list --no-sandbox --user-data-dir=/tmp/vscode-root
1 2 3 4 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
1 2 sudo apt update sudo apt upgrade -y
依赖、工具安装 1 2 3 4 5 sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip sudo apt-get install curl git python3 sudo apt-get install openjdk-11-jdk git config --global user.name 'xxx' git config --global user.email 'xxx@xxx.com'
repo下载
1 2 3 4 mkdir ~/bin PATH=~/bin:$PATH curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo chmod +x ~/bin/repo
初始化仓库并指定分支 1 repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-13.0.0_r7
这里的android-13.0.0_r7按照自己的手机型号进行选择 这里先创建工作文件夹
1 2 3 mkdir android-13 cd android-13 export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
这里我选择使用ssh链接(后面也要用 防止杀进程)
同步完成 相当耗时 建议来个快照(双系统当我没说)
修改swap 1 2 3 4 5 6 7 free -m sudo swapoff -a sudo dd if=/dev/zero of=/swapfile bs=1G count=32 sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile /swapfile swap swap sw 0 0
开始编译 1 2 3 source build/envsetup.sh lunch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 pixel@pixel-virtual-machine:~/android-13$ lunch You're building on Linux Lunch menu .. Here are the common combinations: 1. aosp_arm-eng 2. aosp_arm64-eng 3. aosp_barbet-userdebug 4. aosp_bluejay-userdebug 5. aosp_bramble-userdebug 6. aosp_bramble_car-userdebug 7. aosp_car_arm-userdebug 8. aosp_car_arm64-userdebug 9. aosp_car_x86-userdebug 10. aosp_car_x86_64-userdebug 11. aosp_cf_arm64_auto-userdebug 12. aosp_cf_arm64_phone-userdebug 13. aosp_cf_x86_64_foldable-userdebug 14. aosp_cf_x86_64_pc-userdebug 15. aosp_cf_x86_64_phone-userdebug 16. aosp_cf_x86_64_tv-userdebug 17. aosp_cf_x86_auto-userdebug 18. aosp_cf_x86_phone-userdebug 19. aosp_cf_x86_tv-userdebug 20. aosp_coral-userdebug 21. aosp_coral_car-userdebug 22. aosp_flame-userdebug 23. aosp_flame_car-userdebug 24. aosp_oriole-userdebug 25. aosp_oriole_car-userdebug 26. aosp_raven-userdebug 27. aosp_raven_car-userdebug 28. aosp_redfin-userdebug 29. aosp_redfin_car-userdebug 30. aosp_redfin_vf-userdebug 31. aosp_slider-userdebug 32. aosp_sunfish-userdebug 33. aosp_sunfish_car-userdebug 34. aosp_trout_arm64-userdebug 35. aosp_trout_x86-userdebug 36. aosp_whitefin-userdebug 37. aosp_x86-eng 38. aosp_x86_64-eng 39. arm_krait-eng 40. arm_v7_v8-eng 41. armv8-eng 42. armv8_cortex_a55-eng 43. armv8_kryo385-eng 44. beagle_x15-userdebug 45. beagle_x15_auto-userdebug 46. car_ui_portrait-userdebug 47. car_x86_64-userdebug 48. db845c-userdebug 49. gsi_car_arm64-userdebug 50. gsi_car_x86_64-userdebug 51. hikey-userdebug 52. hikey64_only-userdebug 53. hikey960-userdebug 54. hikey960_tv-userdebug 55. hikey_tv-userdebug 56. poplar-eng 57. poplar-user 58. poplar-userdebug 59. qemu_trusty_arm64-userdebug 60. rb5-userdebug 61. sdk_car_arm-userdebug 62. sdk_car_arm64-userdebug 63. sdk_car_portrait_x86_64-userdebug 64. sdk_car_x86-userdebug 65. sdk_car_x86_64-userdebug 66. sdk_pc_x86_64-userdebug 67. silvermont-eng 68. uml-userdebug 69. yukawa-userdebug 70. yukawa_sei510-userdebug Which would you like? [aosp_arm-eng] Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-eng):
这里我选择 24的aosp_oriole-userdebug 直接输入24就行了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-eng): 24 Hint: next time you can simply run 'lunch aosp_oriole-userdebug' ============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=13 TARGET_PRODUCT=aosp_oriole TARGET_BUILD_VARIANT=userdebug TARGET_BUILD_TYPE=release TARGET_ARCH=arm64 TARGET_ARCH_VARIANT=armv8-2a TARGET_CPU_VARIANT=cortex-a55 TARGET_2ND_ARCH=arm TARGET_2ND_ARCH_VARIANT=armv8-a TARGET_2ND_CPU_VARIANT=generic HOST_ARCH=x86_64 HOST_2ND_ARCH=x86 HOST_OS=linux HOST_OS_EXTRA=Linux-6.8.0-90-generic-x86_64-Ubuntu-22.04.5-LTS HOST_CROSS_OS=windows HOST_CROSS_ARCH=x86 HOST_CROSS_2ND_ARCH=x86_64 HOST_BUILD_TYPE=release BUILD_ID=TP1A.221005.002 OUT_DIR=out PRODUCT_SOONG_NAMESPACES=device/google/gs-common/powerstats hardware/google/gchips/gralloc4 hardware/google/av hardware/google/gchips hardware/google/graphics/common hardware/google/graphics/gs101 hardware/google/interfaces hardware/google/pixel device/google/gs101 device/google/gs101/powerstats vendor/google/whitechapel/tools vendor/broadcom/bluetooth vendor/google/camera vendor/google/interfaces vendor/google_devices/common/proprietary/confirmatioui_hal vendor/google_nos/host/android vendor/google_nos/test/system-test-harness vendor/samsung_slsi/telephony/ vendor/arm/mali/valhall device/google/gs101/conf vendor/samsung_slsi/codec2 device/google/gs101/gnss/47765 vendor/google/trusty/common vendor/google/whitechapel/audio/hal vendor/google/whitechapel/audio/interfaces vendor/google/whitechapel/aoc vendor/goodix/udfps/fp_utils vendor/goodix/udfps/g6_trusty vendor/goodix/udfps/g6_aidl_trusty device/google/raviole/powerstats/oriole device/google/raviole vendor/google_devices/raviole/prebuilts
开始编译
这里的线程数看情况来 后面出现什么依赖什么的基本都能修 硬盘有可能会出现不够的情况 具体问题具体
然后就是等待了 虚拟机大概是几个小时起步 本地系统会快很多 要docker编译也不是不行 方法很多 编译完成文件都在/out中