1、背景说明
虚拟机:wsl 2.0 Ubuntu18.04 虚拟机配置:8G内存,1T存储 软件版本:安卓系统目前最高版本是Android S,也就是Android 12 beta版本源码,无任何修改 报错内容:编译至54%时,ninja编译中断,ninja: build stopped: subcommand failed.
代码语言:javascript复制[ 54% 26841/49115] //prebuilts/rust:libtest rustc linux-x86/1.51.0/src/stdlibs/library/test/src/lib.rs
[ 54% 26842/49115] //frameworks/av/services/mediametrics:mediametrics clang main_mediametrics.cpp
[ 54% 26843/49115] Copy: out/target/product/G10/symbols/system/lib/libtest.dylib.so
[ 54% 26844/49115] //frameworks/av/media/libmediatranscoding:mediatranscoding_aidl_interface-ndk_platform clang android/media/TranscodingResultParcel.cpp [com.android.media]
[ 54% 26845/49115] //frameworks/compile/libbcc/bcinfo:libbcinfo header-abi-linker libbcinfo.so.lsdump
FAILED: out/soong/.intermediates/frameworks/compile/libbcc/bcinfo/libbcinfo/android_vendor.31_arm_armv7-a-neon_cortex-a7_shared/libbcinfo.so.lsdump
prebuilts/clang-tools/linux-x86/bin/header-abi-linker -o out/soong/.intermediates/frameworks/compile/libbcc/bcinfo/libbcinfo/android_vendor.31_arm_armv7-a-neon_cortex-a7_shared/libbcinfo.so.lsdump -so out/soong/.intermediates/frameworks/compile/libbcc/bcinfo/libbcinfo/android_vendor.31_arm_armv7-a-neon_cortex-a7_shared/libbcinfo.so -arch arm -Iframeworks/compile/libbcc/bcinfo/include @out/soong/.intermediates/frameworks/compile/libbcc/bcinfo/libbcinfo/android_vendor.31_arm_armv7-a-neon_cortex-a7_shared/libbcinfo.so.lsdump.rsp
Failed to parse JSON: * Line 1, Column 1
Syntax error: value, object or array expected.
ReadDump failed
[ 54% 26846/49115] //prebuilts/gradle-plugin:metalava-gradle-plugin-deps for prebuilts [linux_glibc common]
[ 54% 26847/49115] //external/rust/crates/android_log-sys:libandroid_log_sys rustc src/lib.rs
[ 54% 26848/49115] //frameworks/base/media:media_permission-aidl-cpp clang-tidy android/media/permission/Identity.cpp
[ 54% 26849/49115] //frameworks/av/media/libmediametrics:mediametricsservice-aidl-cpp clang-tidy android/media/IMediaMetricsService.cpp
[ 54% 26850/49115] build out/target/product/G10/gen/META/lic_intermediates/webrtc_agc__agc.meta_lic
[ 54% 26851/49115] //frameworks/av/media/codec2/components/aac:libcodec2_soft_aacdec link libcodec2_soft_aacdec.so
[ 54% 26852/49115] //external/rust/crates/anyhow:libanyhow rustc src/lib.rs
[ 54% 26853/49115] //external/rust/crates/anyhow:libanyhow rustc src/lib.rs
[ 54% 26854/49115] build out/target/product/G10/gen/META/lic_intermediates/libbt-stack.meta_lic
[ 54% 26855/49115] build out/target/product/G10/gen/META/lic_intermediates/audio.a2dp.default.meta_lic
[ 54% 26856/49115] build out/target/product/G10/gen/META/lic_intermediates/libbt-audio-hal-interface.meta_lic
[ 54% 26857/49115] //frameworks/av/media/libmediatranscoding:mediatranscoding_aidl_interface-ndk_platform clang-tidy android/media/TranscodingSessionStats.cpp [com.android.media]
[ 54% 26858/49115] build out/target/product/G10/gen/META/lic_intermediates/avrcp-target-service.meta_lic
[ 54% 26859/49115] //frameworks/av/media/libmediatranscoding:mediatranscoding_aidl_interface-ndk_platform clang-tidy android/media/ITranscodingClientCallback.cpp [com.android.media]
[ 54% 26860/49115] //frameworks/av/media/libmediatranscoding:mediatranscoding_aidl_interface-ndk_platform clang-tidy android/media/TranscodingVideoTrackFormat.cpp [com.android.media]
[ 54% 26861/49115] //frameworks/av/media/libmediatranscoding:mediatranscoding_aidl_interface-ndk_platform clang-tidy android/media/IMediaTranscodingService.cpp [com.android.media]
[ 54% 26862/49115] //frameworks/av/media/libmediatranscoding:mediatranscoding_aidl_interface-ndk_platform clang-tidy android/media/ITranscodingClient.cpp [com.android.media]
[ 54% 26863/49115] //frameworks/av/media/libmediatranscoding:mediatranscoding_aidl_interface-ndk_platform clang-tidy android/media/TranscodingSessionParcel.cpp [com.android.media]
[ 54% 26864/49115] //frameworks/av/media/libmediatranscoding:mediatranscoding_aidl_interface-ndk_platform clang-tidy android/media/TranscodingRequestParcel.cpp [com.android.media]
[ 54% 26865/49115] //art/dexlayout:libart-dexlayout link libart-dexlayout.so [apex31]
[ 54% 26866/49115] //frameworks/av/media/codec2/components/hevc:libcodec2_soft_hevcenc link libcodec2_soft_hevcenc.so
[ 54% 26867/49115] //external/libvpx:libvpx link libvpx.so
[ 54% 26868/49115] //frameworks/av/media/codec2/components/gav1:libcodec2_soft_av1dec_gav1 link libcodec2_soft_av1dec_gav1.so
[ 54% 26869/49115] //external/libvpx:libvpx link libvpx.so
[ 54% 26870/49115] //system/logging/logd:logd link logd
ninja: build stopped: subcommand failed.
19:21:50 ninja failed with: exit status 1
[0;31m#### failed to build some targets (09:08 (mm:ss)) ####[00m
#### failed to exec [make droid dist BUILD_RTK_STYLE_IMAGE=true DIST_DIR=/home/daqiang_ni/samba/airplay75p/vendor/realtek/common/kernel/system/tmp/dist/android] (09:08 (mm:ss)) ####
tcl ret_tclbuild = 1
#### failed to exec [trom_build] (22:50 (mm:ss)) ####
2、尝试方案
报错后尝试多次增量编译,始终在54%作用报错,报错内容一致。
怀疑sync未拉完整,重新repo sync,提示success,再次编译仍报错。
其他同事表示能编译通过,考虑到编译环境不同,采用VMWare虚拟机环境编译,仍97%报相同错误。
尝试make clean,rm -rf out/
清除编译环境后编译,仍报错。
查阅资料提示由于编译时linux内存不足导致编译中断,wsl2 扩展VHD 至10G(方法如下),仍报相同错误。
添加wsl2配置文件
C:UsersuserName路径添加.wslconfig文件
.wslconfig
[wsl2]
memory=10GB
processors=8
.wslconfig内容如上,内存配置为10GB,处理器8核即16线程 重启Ubuntu18.04,查看内存情况,已修改为10GB
代码语言:javascript复制$ free memory -h
total used free shared buff/cache available
Mem: 9.7G 2.6G 1.8G 36K 5.3G 6.9G
Swap: 3.0G 33M 3.0G
3、问题分析及处理
使用如下命令在编译时间隔1秒持续打印linux内存使用情况,当发生报错时内存仅剩110MB左右,基本可以判断是由于编译时系统内存吃紧导致的编译中断
代码语言:javascript复制$watch -d -n 1 free memory -h
Every 1.0s: free memory -h gd08575: Tue Aug 2 09:41:24 2022
total used free shared buff/cache available
Mem: 9.7G 2.9G 912M 36K 5.9G 6.6G
Swap: 3.0G 37M 3.0G
#或者使用命令
代码语言:javascript复制$ while true;do free memory -h;sleep 1;done
total used free shared buff/cache available
Mem: 9.7G 3.5G 4.1G 36K 2.1G 6.0G
Swap: 3.0G 41M 3.0G
total used free shared buff/cache available
Mem: 9.7G 3.3G 4.2G 36K 2.2G 6.1G
Swap: 3.0G 41M 3.0G
...
当报错后查看内存,可用内存大概4GB甚至更少,使用htop命令查看linux进程发现仍有很多编译进程在跑,因此尝试重启wsl2释放内存后再编译
#关闭Ubuntu18.04LTS后,管理员权限打开WindowsPowerShell重启wsl $wsl --shutdown
进入Ubuntu18.05LTS检测内存情况,9GB可用,重试Android 增量编译,编译success!