ubuntu22.04环境鸿蒙全仓代码编译配置 文章目录1. 前言2. wsl内存和swap 虚拟内存的配置3. 安装核心依赖4. 鸿蒙全仓编译1. 前言作为鸿蒙开发人员搭建开发环境是再平常不过的了。使用docker镜像搭建环境请参见我前面的文章wsl2平台鸿蒙全仓docker编译环境快速创建方法。鸿蒙docker镜像创建于几年前使用的是ubuntu18.04发布版本有点旧。不建议在镜像内升级ubuntu版本。现在我们就在ubuntu22.04或以上版本直接配置鸿蒙全仓库代码编译环境。wsl的创建这里就不赘述了。可以参考我的前一篇文章或网络搜索。本文在windows11系统24核CPU32G内存、wsl2环境适配。需要安装repo、python3。wsl安装的磁盘分区需要有300G的空闲空间。apt源设置为国内源自行网络搜索。可以参照–Ubuntu 22.04 APT源修改国内镜像源配置指南pip源设置为阿里等国内源自行网络搜索。可以参照–Ubuntu系统更换国内软件源全攻略从配置到优化。ubuntu22.04的用户建议为非root用户。repo安装# install_repo.shmkdir-p~/.bin/repogitclone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo ~/.bin/repochmodx ~/.bin/repo/repoechoexport PATH~/.bin/repo:$PATH/root/.bashrcsource~/.bashrc验证fbbDESKTOP-8IRJTCN:~/codes/arkcompiler_ets_frontend$ repo--versionrepo not installedrepo launcher version2.8(from /usr/bin/repo)git2.34.1 Python3.10.12(main, Mar32026,11:56:32)[GCC11.4.0]OS Linux6.6.87.2-microsoft-standard-WSL2(#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025)CPU x86_64(x86_64)2.wsl内存和swap虚拟内存的配置修改配置文件C:\Users\xxx\.wslconfig文件内容没有就创建。.wslconfig文件内容[wsl2]memory24GBswap4GBprocessors18guiApplicationsfalse提醒windows重启生效。wsl的swap(虚拟内存够用即可多了会造成windsow非常卡顿影响工作。memory的大小与-j参数有关。-j参数越大memory越大为防止因内存导致编译失败需要合理选择核数。3. 安装核心依赖sudoapt-getinstall-y\binutils binutils-devgitgit-lfs gnupg flex bison gperf\build-essentialzipcurlzlib1g-dev\gcc-multilib g-multilib gcc-arm-linux-gnueabi\libc6-dev-i386 libc6-dev-amd64 lib32ncurses5-dev\x11proto-core-dev libx11-dev lib32z1-dev ccache\libgl1-mesa-dev libxml2-utils xsltprocunzipm4bc\gnutls-bin python3.10 python3-pip ruby genext2fs\device-tree-compilermakelibffi-dev e2fsprogs\pkg-config perl openssl libssl-dev libelf-dev\libdwarf-dev u-boot-tools mtd-utils cpio doxygen\liblz4-tool openjdk-8-jre gcc g texinfo dosfstools\mtoolsdefault-jre default-jdk libncurses5 apt-utils\wgetsconstarrsyncgit-core\libxml2-dev lib32z-dev grsync xxd libglib2.0-dev\libpixman-1-dev kmod jfsutils reiserfsprogs xfsprogs\squashfs libxcursor-dev libxrandr-dev libxinerama-dev4. 鸿蒙全仓编译配置git用户信息gitconfig--globaluser.emailXXXYYY.comgitconfig--globaluser.nameXXX搭建步骤repo init-uhttps://gitcode.com/openharmony/manifest.git-bmaster --no-repo-verify# 初始化repo仓库reposync-c-j12# 同步鸿蒙全仓代码。每个仓库没有分支概念。repo forall-cgit lfs pull# 拉取 Git LFS大文件存储管理的文件bashbuild/prebuilts_download.sh# 编译器及二进制工具编译指令./build.sh --product-name ohos-sdk-j12# sdk编译.输出目录out/sdk/packages/ohos-sdk./build.sh --product-name rk3568--ccache-j12# 32位全编译镜像适用于rk3568开发板。ccache 为本地缓存目录。镜像输出目录out/rk3568/packages/phone/images/单独快速编译指定模块arkui ./build.sh --product-name rk3568 --build-target ace_engine# 不用加-j参数。第二次编译时可以启用--fast-rebuild参数加快二次编译速度。./build.sh --product-name rk3568 --build-target ace_engine_test ace_engine# 测试用例编译编译说明-j(jobs) 编译用内核数量。建议使用物理核数的一半。该参数越大所耗内存越大编译因内存不够失败的风险越大。不用该参数默认使用所有物理内核去编译风险最大。