#Android源码下载、编译、虚拟机
安装必须工具
sudo apt-get install git-core gnupg \
flex bison build-essential zip curl \
zlib1g-dev gcc-multilib g++-multilib \
libc6-dev-i386 libncurses5 lib32ncurses5-dev \
x11proto-core-dev libx11-dev lib32z1-dev \
libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
安装Repo工具
mkdir ~/bin
PATH=~/bin:$PATH
curl -sSL 'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' |base64 -d > ~/bin/repo
chmod a+x ~/bin/repo
配置Git信息
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
创建工程目录
mkdir Android_AOSP
cd Android_AOSP
初始化仓库
修改repo地址,将 ~/bin/repo 中的地址
if not REPO_URL:
REPO_URL = 'https://gerrit.googlesource.com/git-repo
修改为:
if not REPO_URL:
REPO_URL = 'https://gerrit-googlesource.proxy.ustclug.org/git-repo'
查看安装官网,确定具体版本对应的tag
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-11.0.0_r38
同步代码
由于网络不稳定,sync容易中断,创建sync.sh
#!/bin/bash
repo sync -j4
while [ $? -ne 0 ]
do
echo "===========sync failed ,re-sync again==========="
sleep 3
repo sync -j4
done
脚本添加运行权限
chmod a+x sync.sh
运行脚本
./sync.sh
source build/envsetup.sh
lunch xxx
make -jN
先用AvdManager创建一个虚拟机 android11-car
准备虚拟机必备文件:
VerifiedBootParams.textproto
advancedFeatures.ini
build.prop
data/
encryptionkey.img
kernel-ranchu
ramdisk-qemu.img
system.img
userdata.img
vendor-qemu.img
创建release脚本,执行虚拟机必备文件收集,并创建运行脚本
#!/bin/bash
PRODUCT=generic_car_x86_64
WIN_DIR=/d/Android/images/${PRODUCT}
ANDROID_PRODUCT_OUT=out/target/product/${PRODUCT}
EMULATOR_DIR=/mnt/${WIN_DIR}/
EMULATOR_SH=${EMULATOR_DIR}/emulator.sh
# create dir
mkdir -p ${EMULATOR_DIR}
# cp images
cp -avf $ANDROID_PRODUCT_OUT/encryptionkey.img ${EMULATOR_DIR}
cp -avf $ANDROID_PRODUCT_OUT/kernel-ranchu ${EMULATOR_DIR}
cp -avf $ANDROID_PRODUCT_OUT/ramdisk-qemu.img ${EMULATOR_DIR}
cp -avf $ANDROID_PRODUCT_OUT/system-qemu.img ${EMULATOR_DIR}/system.img
cp -avf $ANDROID_PRODUCT_OUT/vendor-qemu.img ${EMULATOR_DIR}
cp -rvf $ANDROID_PRODUCT_OUT/data ${EMULATOR_DIR}
cp -avf $ANDROID_PRODUCT_OUT/advancedFeatures.ini ${EMULATOR_DIR}
#cp -avf $ANDROID_PRODUCT_OUT/userdata-qemu.img ${EMULATOR_DIR}
cp -avf $ANDROID_PRODUCT_OUT/userdata.img ${EMULATOR_DIR}
cp -avf $ANDROID_PRODUCT_OUT/system/build.prop ${EMULATOR_DIR}
cp -avf $ANDROID_PRODUCT_OUT/VerifiedBootParams.textproto ${EMULATOR_DIR}
#cp -avf $ANDROID_PRODUCT_OUT/source.properties ${EMULATOR_DIR}
echo "#!/bin/bash" > ${EMULATOR_SH}
echo "DIR=${WIN_DIR}" >> ${EMULATOR_SH}
echo "emulator -avd android11-car \\
-verbose \\
-show-kernel \\
-shell \\
-memory 8192 \\
-no-snapshot-load \\
-skin 1280x800 \\
-writable-system \\
-system \${DIR}/system.img \\
-sysdir \${DIR}" >> ${EMULATOR_SH}
echo "# when system.img has been reload, we should run with param: -wipe-data" >> ${EMULATOR_SH}
运行虚拟机
windows端执行release目标目录中的emulator.sh脚本
异常处理
remount
添加运行参数 -writable-system
黑屏
添加运行参数 -wipe-data