前置条件
- macOS Sonoma (14.2.1) 强烈建议至少是这个版本的系统,更早的系统虚拟机稳定性存在问题 ( Fatal Error Encountered: Rosetta 2 Emulation with Java VM Inside Container #7068 )
- MacBook Pro 2023-Apple M2 Pro (4能效核、8性能核、32GB内存、2TB磁盘)
- Homebrew (4.0.28 或更高版本)
- Docker Desktop (4.27.2 或更高版本,从 4.27.0 版本开始集成文件系统报错问题的修正补丁(synchronized filesystem caches))
根据 Google 官方文档,2021年6月22日之后的Android系统版本不支持在macOS系统上构建,我们在 Applic Silicon 的 macOS 系统是不能直接成功构建后续版本的,但是之前的版本可以在修改编译配置后成功编译,只是是否能正常运行存疑。
另外,我们需要安装 Rosetta 2 支持运行部分 x86_64 应用。注意 Rosetta 2 只支持 64 位应用,不支持 32 位应用。 参考 Does Rosetta 2 support 32-bit Intel apps?
准备环境
创建大小写敏感分区
创建大小写敏感的 APFS 卷宗,相对于文件镜像,性能更好,尤其是针对 TimeMachine 更加友好。参考如下命令:
1 |
$ diskutil apfs addVolume disk1 'Case-sensitive APFS' aosp |
注意:
上述命令可能失败:
123456 $ diskutil apfs addVolume disk1 'Case-sensitive APFS' aospWill export new APFS (Case-sensitive) Volume "aosp" from APFS Container Reference disk1Started APFS operation on disk1Preparing to add APFS Volume to APFS Container disk1Error: -69493: You can't add any more APFS Volumes to its APFS Container原因为系统上的磁盘文件名可能已经不是 disk1 ,有可能已经变成 disk2 或者 disk3 ... 具体的磁盘名,参考下图:
安装依赖
1 2 |
# 安装 Rosetta 2 支持 x86_64 应用 $ /usr/sbin/softwareupdate --install-rosetta --agree-to-license |
安装Docker Desktop
去 Docker Desktop 官网,安装最新版本的 Docker Desktop 安装包。
配置 Docker Desktop
启用 Docker Desktop 对于 x86_64 的支持
配置 Docker Desktop 可以调用的 CPU,内存,磁盘等资源
自定义Docker镜像脚本
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 |
FROM ubuntu:jammy # ENV http_proxy http://192.168.1.1:1082 # ENV https_proxy http://192.168.1.1:1082 RUN apt-get update && apt-get install -y gnupg wget # Install required packages RUN apt-get update -qq \ && apt-get upgrade -y -qq \ && apt-get -y install texinfo git repo xz-utils ccache zip unzip \ && apt-get -y install python2-dev python2 python-dev-is-python3 \ && apt-get -y install openjdk-11-jdk rsync # 解决 # prebuilts/clang/host/linux-x86/clang-3289846/bin/clang.real: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory RUN apt-get -y install libncurses5 RUN apt-get clean RUN git config --system user.email "user@email.com" RUN git config --system user.name "user" ARG USER=ubuntu ARG PASSWORD=password RUN useradd -m ${USER} && echo "${USER}:${PASSWORD}" | chpasswd && adduser ${USER} sudo USER ${USER} WORKDIR /home/${USER} CMD "/bin/bash" |
构建编译镜像
1 |
$ docker build --platform linux/amd64,linux/arm64 -f Dockerfile -t docker-aosp-jammy . |
运行镜像
1 2 3 4 5 |
$ docker run -it --rm \ --name docker-aosp-jammy \ -v /Volumes/aosp:/home/ubuntu \ -w /home/ubuntu \ docker-aosp-jammy:latest |
代码拉取&构建
1.使用镜像下载Android
源代码
清华大学的镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# 建议直接下载压缩包,使用repo更新基本上都会失败,即使用国内镜像也是一样(目前大约96GB) # 不建议直接在aosp根目录下直接操作,由于APFS创建的卷宗根目录下会放置回收站 .Trashes 因此编译的时候可能会报错: # opendir failed: .Trashes: Operation not permitted # 建议通过直接清华源的镜像压缩包进行代码同步 # 不要通过 repo sync 进行,目前测试发现 repo sync 成功的概率越来越低了 $ curl -OC - https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar $ tar xvf aosp-latest.tar $ cd aosp |
2.编译源代码
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 |
# 查看分支 # cd .repo/manifests # git branch -a | grep "android-12" # 检出代码代码 # repo init -b android-10.0.0_r47 $ repo init -b android-12.1.0_r26 $ repo sync -j4 --fail-fast $ export USE_CCACHE=1 # 需要移除 nsjail 否则无法启动编译 $ mv prebuilts/build-tools/linux-x86/bin/nsjail prebuilts/build-tools/linux-x86/bin/nsjail.old # 执行构建 $ source build/envsetup.sh # 默认编译的镜像是 release 模式的,运行速度更快,但是不方便系统调试 # 如果需要跟踪调试代码,建议编译为调试类型 # export TARGET_BUILD_TYPE=debug # 纯ARM64系统镜像,可以刷机 # lunch aosp_arm64-eng # eng:代表 engineer,开发工程师的版本,拥有最大的权限(root等),具有额外调试工具的开发配置。 # 执行 lunch 命令可以输出全部的编译目标列表 # 更多的编译选项可以从 build/make/target/product/ 下看到 # 模拟器使用的系统镜像 # lunch sdk_phone_arm64-userdebug $ lunch sdk_phone_arm64-eng $ m |
注意,如果执行
1 |
lunch sdk_phone_arm64-eng |
的时候长时间卡住,Ctrl + C 停止之后报错:
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
ubuntu@ubuntu:~/aosp$ lunch sdk_phone_arm64-eng 06:19:01 Got signal: interrupt 06:19:01 Got signal: interrupt 06:19:01 Still alive, killing subprocesses... 06:19:02 Got signal: interrupt 06:19:02 Still alive, cleaning up... 06:19:02 Timed out exiting... panic: write to panicWriter goroutine 281325 [running]: android/soong/ui/logger.panicWriter.Write(...) build/soong/ui/logger/logger.go:185 log.(*Logger).Output(0xc0001660a0, 0x3, 0xc000c74e80, 0x15, 0x0, 0x0) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/log/log.go:172 +0x287 android/soong/ui/logger.(*stdLogger).Output(0xc000150210, 0x2, 0xc000c74e80, 0x15, 0x15, 0x7f1d68) build/soong/ui/logger/logger.go:223 +0x88 android/soong/ui/logger.(*stdLogger).Panicln(0xc000150210, 0xc00c028070, 0x1, 0x1) build/soong/ui/logger/logger.go:318 +0x78 android/soong/ui/build.handleSignals.func1.1(0x7f1d20, 0xc000150210, 0xc0001701e0) build/soong/ui/build/signal.go:71 +0xaa created by android/soong/ui/build.handleSignals.func1 build/soong/ui/build/signal.go:68 +0x105 goroutine 1 [chan receive]: os/exec.(*Cmd).Wait(0xc0057ce000, 0x0, 0x0) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/exec/exec.go:509 +0x125 os/exec.(*Cmd).Run(0xc0057ce000, 0xc007804000, 0x0) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/exec/exec.go:341 +0x5c os/exec.(*Cmd).CombinedOutput(0xc0057ce000, 0xc0068ca010, 0x1, 0x1, 0xe, 0xc0057ce000) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/exec/exec.go:561 +0x91 android/soong/ui/build.(*Cmd).sandboxSupported.func1() build/soong/ui/build/sandbox_linux.go:87 +0x3b4 sync.(*Once).doSlow(0x9fcac0, 0xc0002f1218) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/sync/once.go:66 +0xe3 sync.(*Once).Do(...) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/sync/once.go:57 android/soong/ui/build.(*Cmd).sandboxSupported(0xc009acd800, 0x0) build/soong/ui/build/sandbox_linux.go:69 +0x8e android/soong/ui/build.(*Cmd).prepare(0xc009acd800) build/soong/ui/build/exec.go:56 +0x3f android/soong/ui/build.(*Cmd).Start(0xc009acd800, 0x0, 0x0) build/soong/ui/build/exec.go:64 +0x2b android/soong/ui/build.(*Cmd).StartOrFatal(0xc009acd800) build/soong/ui/build/exec.go:88 +0x2f android/soong/ui/build.dumpMakeVars(0xc0000c4480, 0xc000188000, 0x0, 0x0, 0x0, 0xc0039a2f00, 0x2e, 0x2f, 0x0, 0x0, ...) build/soong/ui/build/dumpvars.go:108 +0x693 android/soong/ui/build.DumpMakeVars(0xc0000c4480, 0xc000188000, 0x0, 0x0, 0x0, 0xc0039a2c00, 0x2f, 0x30, 0x0, 0x0, ...) build/soong/ui/build/dumpvars.go:68 +0x708 main.dumpVars(0xc0000c4480, 0xc000188000, 0xc0000c4140, 0x4, 0x4, 0xc0000b1238, 0x3) build/soong/cmd/soong_ui/main.go:316 +0x5d9 main.main() build/soong/cmd/soong_ui/main.go:206 +0x12ab goroutine 35 [syscall]: os/signal.signal_recv(0x7e9f80) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/runtime/sigqueue.go:147 +0x9c os/signal.loop() /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/signal/signal_unix.go:23 +0x22 created by os/signal.init.0 /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/signal/signal_unix.go:29 +0x41 goroutine 37 [select]: android/soong/ui/build.handleSignals(0xc00009a180, 0x7f1d20, 0xc000150210, 0xc000152050, 0xc0001701e0) build/soong/ui/build/signal.go:79 +0x136 created by android/soong/ui/build.SetupSignals build/soong/ui/build/signal.go:44 +0x136 goroutine 281322 [IO wait, 4 minutes]: internal/poll.runtime_pollWait(0x7ffffc2dcea8, 0x72, 0xffffffffffffffff) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/runtime/netpoll.go:184 +0x55 internal/poll.(*pollDesc).wait(0xc0005b2078, 0x72, 0x201, 0x216, 0xffffffffffffffff) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/internal/poll/fd_poll_runtime.go:87 +0x45 internal/poll.(*pollDesc).waitRead(...) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/internal/poll/fd_poll_runtime.go:92 internal/poll.(*FD).Read(0xc0005b2060, 0xc00001a9ea, 0x216, 0x216, 0x0, 0x0, 0x0) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/internal/poll/fd_unix.go:169 +0x1cf os.(*File).read(...) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/file_unix.go:259 os.(*File).Read(0xc0068c8008, 0xc00001a9ea, 0x216, 0x216, 0x3d, 0x0, 0x0) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/file.go:116 +0x71 bytes.(*Buffer).ReadFrom(0xc007804000, 0x7e77c0, 0xc0068c8008, 0x7ffffc258028, 0xc007804000, 0x78f801) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/bytes/buffer.go:204 +0xb4 io.copyBuffer(0x7e7420, 0xc007804000, 0x7e77c0, 0xc0068c8008, 0x0, 0x0, 0x0, 0x4562d0, 0xc006175fa0, 0x406885) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/io/io.go:388 +0x2ed io.Copy(...) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/io/io.go:364 os/exec.(*Cmd).writerDescriptor.func1(0xc006175fc0, 0x5d3fd5) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/exec/exec.go:311 +0x63 os/exec.(*Cmd).Start.func1(0xc0057ce000, 0xc0073b4080) /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/exec/exec.go:435 +0x27 created by os/exec.(*Cmd).Start /home/ubuntu/aosp/prebuilts/go/linux-x86/src/os/exec/exec.go:434 +0x608 |
则观察当前执行的进程,会发现名为 nsjail 的进程长时间卡住,并且 100% CPU 占用,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
ubuntu@ubuntu:~/aosp$ top top - 06:19:16 up 3:16, 2 users, load average: 1.02, 1.00, 0.90 Tasks: 175 total, 2 running, 173 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.6 us, 7.8 sy, 0.0 ni, 91.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 26003.1 total, 2185.0 free, 491.4 used, 23326.8 buff/cache MiB Swap: 8192.0 total, 8185.2 free, 6.8 used. 25160.6 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 38314 ubuntu 20 0 1198852 3496 1116 R 100.0 0.0 4:30.61 nsjail 93 root 20 0 0 0 0 I 0.3 0.0 0:01.22 kworker/7:1-eve+ 1 root 20 0 19028 9232 6024 S 0.0 0.0 0:01.96 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.04 kthreadd 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp 5 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 slub_flushwq 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns 8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-ev+ 10 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq |
nsjail 是 Android 用于建立隔离环境,防止进程之间相互干扰的一个沙箱工具,功能类似 Docker 。
应用位于源代码的位置: prebuilts/build-tools/linux-x86/bin/nsjail
Rosetta 转译造成应用运行异常,最简单的方案,就是直接重命名或者删除 prebuilts/build-tools/linux-x86/bin/nsjail,让编译工具找不到 nsjail, 不使用沙箱进行编译即可。
如下:
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 |
ubuntu@ubuntu:~/aosp$ mv prebuilts/build-tools/linux-x86/bin/nsjail prebuilts/build-tools/linux-x86/bin/nsjail.old ubuntu@ubuntu:~/aosp$ lunch sdk_phone_arm64-eng 06:58:21 Build sandboxing disabled due to nsjail error. ============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=11 TARGET_PRODUCT=sdk_phone_arm64 TARGET_BUILD_VARIANT=eng TARGET_BUILD_TYPE=release TARGET_ARCH=arm64 TARGET_ARCH_VARIANT=armv8-a TARGET_CPU_VARIANT=generic 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-5.15.0-86-generic-x86_64-Ubuntu-22.04.3-LTS HOST_CROSS_OS=windows HOST_CROSS_ARCH=x86 HOST_CROSS_2ND_ARCH=x86_64 HOST_BUILD_TYPE=release BUILD_ID=RSV1.210329.100 OUT_DIR=out PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera device/generic/goldfish device/generic/goldfish-opengl ============================================ |
针对警告 “Build sandboxing disabled due to nsjail error.” 可以直接无视。
如果报错:
1 2 3 4 |
info: A new version of repo is available warning: repo is not tracking a remote branch, so it will not receive updates repo reset: 错误:Entry 'README.md' not uptodate. Cannot merge. 致命错误:不能重置索引文件至版本 'v2.37^0'。 |
则说明当前的 repo 版本太低,需要更新到最新版本。
执行如下命令:
1 2 3 |
$ cd .repo/repo $ git pull |
如果报错:
1 2 3 4 5 6 |
FAILED: out/soong/.primary/soong-ui-build/test/test.passed out/soong/.bootstrap/bin/gotestrunner -p ./build/soong/ui/build -f out/soong/.primary/soong-ui-build/test/test.passed -- out/soong/.primary/soong-ui-build/test/test -test.short --- FAIL: TestTrylock (0.32s) proc_sync_test.go:154: Permitted locking fileLock twice. Subprocess output: "Will lock path \"/home/ubuntu/aosp/out/soong/.temp/soong_lock_test666225564\"\nTried to lock path /home/ubuntu/aosp/out/soong/.temp/soong_lock_test666225564. Received error <nil>. Exiting with status 0\n" FAIL 04:34:45 ninja failed with: exit status 1 |
这个需要修改源代码去除 build/soong/ui/build/proc_sync_test.go 对于文件锁定的检测代码,注释去掉如下代码:
1 2 3 4 5 6 7 8 |
func TestTrylock(t *testing.T) { lockpath := os.Getenv(lockPathVariable) if len(lockpath) < 1 { checkTrylockMainProcess(t) } else { getLockAndExit(lockpath) } } |
如果报错:
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 79 80 81 82 83 84 85 |
FAILED: out/target/common/obj/PACKAGING/core_dex_intermediates/classes.dex /bin/bash -c "(mkdir -p out/target/common/obj/PACKAGING/core_dex_intermediates/tmp ) && (rm -f out/target/common/obj/PACKAGING/core_dex_intermediates/classes*.dex out/target/common/obj/PACKAGING/core_dex_intermediates/d8_input.jar ) && (out/soong/host/linux-x86/bin/zip2zip -j -i prebuilts/sdk/current/system/android.jar -o out/target/common/obj/PACKAGING/core_dex_intermediates/d8_input.jar \"**/*.class\" ) && (out/soong/host/linux-x86/bin/d8 -JXms16M -JXmx2048M -JXX:OnError='cat hs_err_pid%p.log' -JXX:CICompilerCount=6 -JXX:+UseDynamicNumberOfGCThreads --output out/target/common/obj/PACKAGING/core_dex_intermediates/tmp --min-api 1000 out/target/common/obj/PACKAGING/core_dex_intermediates/d8_input.jar ) && (mv out/target/common/obj/PACKAGING/core_dex_intermediates/tmp/* out/target/common/obj/PACKAGING/core_dex_intermediates/ ) && (rm -f out/target/common/obj/PACKAGING/core_dex_intermediates/d8_input.jar ) && (rm -rf out/target/common/obj/PACKAGING/core_dex_intermediates/tmp )" Warning: An API level of 1000 is not supported by this compiler. Please use an API level of 30 or earlier # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007ffffeca1af0, pid=503429, tid=508159 # # JRE version: OpenJDK Runtime Environment (11.0.4) (build 11.0.4+0-5935077) # Java VM: OpenJDK 64-Bit Server VM (11.0.4+0-5935077, mixed mode, tiered, compressed oops, g1 gc, linux-amd64) # Problematic frame: # V [libjvm.so+0x6a1af0] void G1ParScanThreadState::do_oop_evac<oopDesc*>(oopDesc**)+0x10 # # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /home/ubuntu/aosp/core.503429) # # An error report file with more information is saved as: # /home/ubuntu/aosp/hs_err_pid503429.log # # If you would like to submit a bug report, please visit: # http://bugreport.java.com/bugreport/crash.jsp # # # -XX:OnError="cat hs_err_pid%p.log" # Executing /bin/sh -c "cat hs_err_pid503429.log" ... # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007ffffeca1af0, pid=503429, tid=508159 # # JRE version: OpenJDK Runtime Environment (11.0.4) (build 11.0.4+0-5935077) # Java VM: OpenJDK 64-Bit Server VM (11.0.4+0-5935077, mixed mode, tiered, compressed oops, g1 gc, linux-amd64) # Problematic frame: # V [libjvm.so+0x6a1af0] void G1ParScanThreadState::do_oop_evac<oopDesc*>(oopDesc**)+0x10 # # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /home/ubuntu/aosp/core.503429) # # If you would like to submit a bug report, please visit: # http://bugreport.java.com/bugreport/crash.jsp # --------------- S U M M A R Y ------------ Command Line: -Xms16M -Xmx2048M -XX:OnError=cat hs_err_pid%p.log -XX:CICompilerCount=6 -XX:+UseDynamicNumberOfGCThreads com.android.tools.r8.D8 --output out/target/common/obj/PACKAGING/core_dex_intermediates/tmp --min-api 1000 out/target/common/obj/PACKAGING/core_dex_intermediates/d8_input.jar Host: x86_64, 12 cores, 25G, Ubuntu 22.04.3 LTS Time: Thu Oct 19 08:39:10 2023 UTC elapsed time: 39 seconds (0d 0h 0m 39s) --------------- T H R E A D --------------- Current thread (0x00007fffc4162800): GCTaskThread "GC Thread#7" [stack: 0x00007fff961ea000,0x00007fff962ea000] [id=508159] Stack: [0x00007fff961ea000,0x00007fff962ea000], sp=0x00007fff962e8bc0, free space=1018k Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0x6a1af0] void G1ParScanThreadState::do_oop_evac<oopDesc*>(oopDesc**)+0x10 V [libjvm.so+0x69f2dc] G1ParEvacuateFollowersClosure::do_void()+0xdc V [libjvm.so+0x6a30d6] G1ParTask::work(unsigned int)+0x146 V [libjvm.so+0xc66bdd] GangWorker::loop()+0x4d V [libjvm.so+0xbd7750] Thread::call_run()+0x60 V [libjvm.so+0xa824fe] thread_native_entry(Thread*)+0x1ce siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000000 .................................................. 7ffffd8ff000-7ffffda00000 rw-p 00000000 00:00 0 7ffffda00000-7ffffda1b000 r-xp 00000000 fc:02 11824118 /home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/lib/libzip.so 7ffffda1b000-7ffffdc1b000 ---p 0001b000 fc:02 11824118 /home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/lib/libzip.so 7ffffdc1b000-7ffffdc1c000 r--p 0001b000 fc:02 11824118 /home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/lib/libzip.so 7ffffdc1c000-7ffffdc1d000 rw-p 0001c000 fc:02 11824118 /home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/lib/libzip.so 7ffffdc27000-7ffffdc7e000 r--p 00000000 fc:02 12059906 /usr/lib/locale/C.utf8/LC_CTYPE 7ffffdc7e000-7ffffde00000 rw-p 00000000 00:00 0 7ffffde00000-7ffffde25000 r-xp 00000000 fc:02 11824096 /home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/lib/libjava.so 7ffffde25000-7ffffe025000 ---p 00025000 fc:02 11824096 /home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/lib/libjava.so 7ffffe025000-7ffffe026000 r--p 00025000 fc:02 11824096 /home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/lib/libjava.so 7ffffe026000-7ffffe027000 rw-p 00026000 fc:02 11824096 /home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/lib/libjava.so .................................................. Memory: 4k page, physical 26627212k(4172424k free), swap 8388604k(8384596k free) vm_info: OpenJDK 64-Bit Server VM (11.0.4+0-5935077) for linux-amd64 JRE (11.0.4+0-5935077), built on Oct 11 2019 19:04:17 by "androidbuild" with gcc 4.2.1 Compatible Android (5657785 based on r353983d) Clang 9.0.4 (https://android.googlesource.com/toolchain/llvm-project 2a90cc9d899e6fe6dcf0da193244b25f75735c7b) .................................................. |
报错内容提示的是 OpenJDK 64-Bit Server VM (11.0.4+0-5935077) for linux-amd64 运行异常。
而 Java 代码完全可以使用 ARM64 版本的 Java 进行编译。
我们可以链接 ARM64 的 Java 编译器到指定的目录,执行如下命令:
1 2 3 4 5 6 7 8 9 10 |
ubuntu@ubuntu:~/aosp$ sudo apt install openjdk-11-jdk ubuntu@ubuntu:~/aosp$ mv prebuilts/jdk/jdk11/linux-x86/bin prebuilts/jdk/jdk11/linux-x86/bin.bak ubuntu@ubuntu:~/aosp$ ln -s /usr/lib/jvm/java-11-openjdk-arm64/bin prebuilts/jdk/jdk11/linux-x86/bin # 此处,我们需要完整删除以前构建残留,否则可能会发生后续无法链接文件的问题 ubuntu@ubuntu:~/aosp$ rm -rf out ubuntu@ubuntu:~/aosp$ m |
运行镜像
选择 system-qemu.img 和 vendor-qemu.img,这两个镜像是专门为 qemu 运行制作的,如果选择 system.img 和 vendor.img,则 avd 运行失败。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ cd /Volumes/aosp $ export ANDROID_BUILD_TOP=/Volumes/aosp/aosp $ export ANDROID_PRODUCT_OUT=$ANDROID_BUILD_TOP/out/target/product/emulator_arm64 $ export OUT=$ANDROID_PRODUCT_OUT # 如果报错 Could not launch '/Users/`whoami`/Library/Android/sdk/emulator/qemu/darwin-x86_64/qemu-system-aarch64': No such file or directory # 则执行如下命令 # cp -r /Users/`whoami`/Library/Android/sdk/emulator/qemu/darwin-aarch64 /Users/`whoami`/Library/Android/sdk/emulator/qemu/darwin-x86_64 # 使用Android SDK自带的模拟器启动,源代码中自带的模拟器性能很差 $ /Users/`whoami`/Library/Android/sdk/tools/emulator -verbose -show-kernel |
上面运行起来的镜像是从 /Volumes/aosp/aosp/out/target/product/emulator_arm64/hardware-qemu.ini
读取配置信息的,但是这个文件直接修改无效。我们如果需要修改参数,只能从启动参数中设置。
比如我们如果需要增大内存,开启 GPU
的支持,则执行如下命令:
1 |
$ /Users/`whoami`/Library/Android/sdk/tools/emulator -gpu on -memory 4096 -verbose -show-kernel |
参考链接
- macOS Big Sur(11.7.5)编译Android 12.0源码过程总结
- ubuntu 20.04编译Android 11源代码&模拟器
- macOS Big Sur 编译Android11.0源码过程总结
- 代号、标记和 build 号
- AOSP 编译Android12源码全记录
- Android 开发者代码实验室
- macOS Sierra (10.12.3)上编译ARM版本Android 5.1.1_r38 (Lollipop)源代码
- How can I download and install macOS 10.12 SDK?
- Fix depends on disabled module "libbit_field_derive" error when building.
- 搭建编译环境
- [android-building] Platform development on MacOS isn't supported as of June 22, 2021.
- Can I download AOSP and compile the Android OS on a MacBook or other macOS device?
- Platform development on MacOS isn't supported as of June 22, 2021.
- Building Android 11 for x86 with ARM compatibility
- 使用VsCode调试Android Framework C/C++源代码
- How to build AOSP on M1
- Error in compiling android (12) aosp on mac 13.3 m1 max
- Intel/Apple Silicon架构MacOS平台编译AOSP源码
- 在Mac平台使用Docker搭建AOSP(Android源代码)编译环境
- ubuntu 22.04.2编译Android 12.1源代码&模拟器
- 五、Docker 数据持久化存储与性能调优
- 如何提高 Docker 在 Mac 下的文件读写速度?
- 如何提升Docker for Mac性能
- docker性能分析命令 docker 磁盘性能 转载
- Speed boost achievement unlocked on Docker Desktop 4.6 for Mac
- File system performance improvements #1592
- Docker volumes 挂载时 cached 和 delegated 的区别和选择
- Docker 优化之 Docker-sync 解决 Docker 挂载缓慢
- Enabling aarch64 as a host architecture for Android Build (WIP)
- Re: [android-building] AOSP on aws a1 instance (arm)
- [Docker Desktop for Mac] - Support for running x86-64 binaries with Rosetta 2
- M1 和 Docker 谈了个恋爱
- Using Rosetta in a UTM Linux VM with Docker on Apple Silicon
- Running Intel Binaries in Linux VMs with Rosetta
- WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)
- Docker多架构支持-buildx构建多架构镜像
- Liviable now shares folders in Linux VMs, and should support Rosetta 2
- Running Intel Binaries in Linux VMs with Rosetta
- Rosetta in Docker
- macOS-Linux-VM-with-Rosetta
- 利用 Lima 在 M1 執行 x86 的 Ubuntu
- Compare Podman Desktop vs lima and see what are their differences.
- UTM:开源的多面手 macOS 虚拟机(更新到 2023.8.20)
- WSL Ubuntu 20.04下Android源码编译与导入Android Studio
- WSL进行aosp下载编译
- UTM:开源的多面手 macOS 虚拟机(更新到 2023.8.20)
- ubuntu server硬盘扩容(LVM)
- Build sandboxing disabled due to docker
- "Build sandboxing disabled due to nsjail error. This may become fatal in the future."
- google/nsjail
- Intel-on-ARM and ARM-on-Intel
- Intel/Apple Silicon架构MacOS平台编译AOSP源码
- MacOSX 11.6 下编译 AOSP android11 系统源代码
- FAILED: out/target/product/generic_arm64/obj/PACKAGING/vndk_intermediates/check-list-timestamp
- android-emulator-m1-preview
- 模拟器版本说明
- repo sync出现contains uncommitted changes错误解决办法
- boringssl_self_test_apex64 error, endless boot loop, emulator screen stuck on "Connecting to the Emulator"
- AVD (API 31) black screen
- Android-11 build for Raspberry Pi4
- arpi 11 : framework patch
- Build faild #71
- Android Emulator MacOS Development
- [android-kernel环境搭建]emulator_kernel
- AOSP sepolicy_tests_intermediates/sepolicy_tests error on building using MAC Catalina
- android/prebuilts/qemu-kernel
- make public aosp 11/10 build and run on M1
- Rosetta results with error for any AMD64 binary #5567
- Linux 使用strace命令查找进程卡死原因
- 内核futex的BUG导致程序hang死问题排查
- How to Install the Latest Mainline Linux Kernel Version in Ubuntu [GUI and Terminal Methods]
- Android Clang/LLVM Toolchain
- Android Clang/LLVM Prebuilts
- Android8.1源码编译问题集锦
- Source build Error Help #355
- Android dex2oat build:ERROR: Dex2oat failed to compile a boot image
- Compiling a deodexed AOSP?
- docker/roadmap
- [Docker Desktop] Improve Mac File system performance #7
- Volume synchronization bug on M1 Mac #6219
- virtiofs breaks initial startup of Postgres container #6270
你好!这里我没看明白,sudo apt install openjdk-11-jdk,安装的应该是 x86_64 的 jdk 吧?怎么得到了 usr/lib/jvm/java-11-openjdk-arm64 这种 arm64 的 jdk 呢?求解,感谢!
我这个地方写的不够规范,应该是 docker build --platform linux/amd64,linux/arm64 -f Dockerfile -t docker-aosp-jammy . 才对,构建的是多镜像平台才对,刚刚改过来了。
macOS系统上安装的虚拟机是ARM64的 ubuntu ,然后在 ARM64的ubuntu上通过 Rosetta 2 运行 x86的应用程序。因为 macOS 自身运行在ARM的CPU上,安装 ARM版本的ubuntu 可以直接通过ARM指令运行,没有任何转换开销。如果安装 x86 版本的 ubuntu 的话,性能就非常差了。
噢噢,试过了,docker 编译太慢了,尤其是读取文件。试了用OrbStack (https://orbstack.dev) 运行x86_64的Ubuntu会快很多很多!缺点是在编译最后构建.img镜像时失败了,试了把工作目录所在的APFS分区改为用ETX4分区更不行,直接Too many open files错误。