AOSP编译问题

文章描述了在编译AndroidSDK时遇到的各种错误及解决方案,包括lunchsdk命令失败、rsync未安装、dex2oat开启导致的问题、mke2fs参数错误、python版本不兼容以及编译过程中改变out目录导致的报错,并提供了相应的解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编译android sdk

lunch sdk_x86_64-eng 命令报错

FAILED: out/soong/build.ninja
cd "$(dirname "out/host/linux-x86/bin/soong_build")" && BUILDER="$PWD/$(basename "out/host/linux-x86/bin/soong_build")" && cd / && env -i  "$BUILDER"     --top "$TOP"     --soong_out "out/soong"     --out "out"     -o out/soong/build.ninja --globListDir build --globFile out/soong/globs-build.ninja -t -l out/.module_paths/Android.bp.list --available_env out/soong/soong.environment.available --used_env out/soong/soong.environment.used.build Android.bp
error: packages/modules/RuntimeI18n/apex/Android.bp:67:1: dependency "art-bootclasspath-fragment" of "i18n-bootclasspath-fragment" missing variant:
  apex:com.android.art
available variants:
  os:android,arch:common
error: packages/modules/RuntimeI18n/apex/Android.bp:67:1: dependency "prebuilt_art-bootclasspath-fragment" of "i18n-bootclasspath-fragment" missing variant:
  apex:com.android.art
available variants:
  os:android,arch:common
05:10:29 soong bootstrap failed with: exit status 1

#### failed to build some targets (04:30 (mm:ss)) ####

解决:
修改对应文件:aosp/build/target/product/sdk_x86_64.mk,增加两行,重新编译

$(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_phone_x86_64.mk)

# 增加此处两行
# Always build modules from source
PRODUCT_MODULE_BUILD_FROM_SOURCE := true

PRODUCT_NAME := sdk_x86_64

参考

问题:未安装rsync

/bin/bash: line 1: rsync: command not found

解决:安装rsync

sudo pacman -S rsync

问题:默认情况在linux编译系统 会开启odex的。

Fault message: Check failed: map.IsValid() Failed anonymous mmap((nil), 131072, 0x3, 0x22, -1, 0): Cannot allocate memory. See process maps in the log.
ERROR: Dex2oat failed to compile a boot image.It is likely that the boot classpath is inconsistent.Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.
04:07:58 ninja failed with: exit status 1

#### failed to build some targets (13:29 (mm:ss)) ####

解决:编译前关闭dex2oat

export WITH_DEXPREOPT=false

问题:mke2fs参数导致

Creating regular file /data/aosp/out/soong/.temp/tmptQHrWf/content/apex_payload.img
Invalid filesystem option set: has_journal,extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file

AssertionError: Failed to execute: out/soong/host/linux-x86/bin/mke2fs -O ^has_journal -b 4096 -m 0 -t ext4 -I 256 -N 162 -U 7d1522e1-9dfa-5edb-a43e-98e3a4d20250 -E hash_seed=7d1522e1-9dfa-5edb-a43e-98e3a4d20250 /data/aosp/out/soong/.temp/tmptQHrWf/content/apex_payload.img 163M

解决:修改mke2fs的配置文件。

cp  /etc/mke2fs.conf /etc/mke2fs.conf.bak #备份
vim /etc/mke2fs.conf # 修改

将下面部分
ext4 = {
features = has_journal,extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file
}

修改为
ext4 = {
features = has_journal
}

后记:
开始以为是磁盘的xfs格式导致,后来利用Create a File Image Container or Filesystem in a File的方法测试后发现不是磁盘格式问题

测试步骤:用mke2fs制作img镜像文件

truncate --size=100M myfs.img
dd if=/dev/zero of=myfs.img count=204800
sudo mkfs.ext4 myfs.img
sudo mke2fs -t ext4 myfs.img

问题:python版本不匹配

FAILED: out/target/product/generic_x86_64/system-qemu.img
/bin/bash -c "(export SGDISK=out/host/linux-x86/bin/sgdisk SIMG2IMG=out/host/linux-x86/bin/simg2img;      device/generic/goldfish/tools/mk_combined_img.py -i out/target/product/generic_x86_64/system-qemu-config.txt -o out/target/product/generic_x86_64/system-qemu.img)"
  File "/data/aosp/device/generic/goldfish/tools/mk_combined_img.py", line 48
    print "'%s' cannot be converted to int" % (line[2])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
10:17:24 ninja failed with: exit status 1

解决:修改python为python2

sudo pacman -S python2 # 安装python2
sudo ln -sb /usr/bin/python2 /usr/bin/python # 新建软链接,备份旧链接

问题:编译期间改变了out目录导致报错

emulator: WARNING: Couldn't find crash service executable /data/aosp/prebuilts/android-emulator/linux-x86_64/emulator64-crash-service

emulator: ERROR: No initial system image for this configuration!

解决:使用emulator -verbose查看详细报错信息,发现是由于使用export OUT_DIR=xx改变了目录,导致目录错乱。
使用evn查看当前环境变量,修改不正确的目录,例如下面,具体要看情况

export ANDROID_HOST_OUT=/data/aosp/out/host/linux-x86
export ANDROID_PRODUCT_OUT=/data/aosp/out/target/product/generic_x86_64
export ANDROID_HOST_OUT_TESTCASES=/data/aosp/out/host/linux-x86/testcases

问题:aidegen命令python版本不兼容

$ aidegen Settings -i s
 
MutableMapping = collections.MutableMapping
AttributeError: module 'collections' has no attribute 'MutableMapping'

解决:由于arch linux当前python版本是python3.10,从 python3.3开始,就使用 from collections.abc import MutableMapping 替代 from collections import Mapping, MutableMapping;
在 python3.10 上,彻底移除了 from collections import Mapping, MutableMapping。

yay -S python38 # 安装python3.8版本
ln -s /usr/bin/python3.8 /usr/bin/python3 #将python3指向python3.8
### 编译 Android 13 AOSP 源码 #### 准备工作环境 为了顺利编译 Android 13 的 AOSP 源码,建议在一个干净的 Ubuntu 20.04 LTS 环境中操作。确保已经安装了必要的依赖包和工具链[^3]。 ```bash sudo apt-get update && sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig ``` #### 安装 Repo 工具并初始化仓库 Repo 是 Google 开发的一个 Python 脚本,用于管理多个 Git 项目。通过它可以从 GitHub 或其他托管服务获取整个 Android 源树。 ```bash mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo ``` 创建一个新的文件夹来保存源代码: ```bash mkdir ~/aosp cd ~/aosp repo init -u https://android.googlesource.com/platform/manifest -b android-13.0.0_rXX # XX代表具体的修订版本号 repo sync --no-tags --no-clone-bundle ``` #### 配置构建环境变量 进入源码根目录设置环境变量以便后续命令能够正常执行: ```bash source build/envsetup.sh lunch aosp_arm-eng ``` `lunch` 命令会配置一系列默认参数,其中 `eng` 表示开发者模式,适合调试;而 `userdebug` 则介于两者之间,更接近生产环境但仍保留一些日志输出功能[^1]。 #### 执行实际编译流程 当一切准备就绪后就可以启动编译过程了。这一步可能耗时较长取决于机器性能以及网络状况等因素影响。 ```bash m -j$(nproc) ``` 上述指令利用多线程加速编译速度(`-j`)选项指定了使用的 CPU 核心数,通常设为当前系统的最大核心数量可以加快进度[^4]。 #### 获取编译成果 一旦编译顺利完成,最终生成的镜像文件将会位于 `out/target/product/<device>/` 文件夹内,具体路径视所选设备型号不同有所变化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值