Ubunut16.04编译Android8.1.0
1. 安装JDK
sudo apt-get update
sudo apt-get install openjdk-8-jdk
2. 设置输出目录
每次编译的输出都会存储在相应源代码树的 your-out-directory子目录下。
要进行这项设置,请导出 OUT_DIR_COMMON_BASE 变量,使其指向将存储输出目录的位置。
export OUT_DIR_COMMON_BASE=<path-to-your-out-directory>
3. 安装 Repo
确保主目录下有一个 bin/ 目录,并且该目录包含在路径中:
mkdir ~/bin
PATH=~/bin:$PATH
下载 Repo 工具,并确保它可执行:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
4. 初始化 Repo 客户端
创建一个空目录来存放您的工作文件。
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
使用您的真实姓名和电子邮件地址配置 Git。
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
5. 下载 Android 源代码树
通过下面命令下载 android-8.1.0_r61 的代码
repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r61
repo sync -c --no-tags
在源码下载过程中遇到的一个问题:
在Android源码拉取过程中,缺少了一个libnativehelper文件目录,需要手动从官网中获取缺少的文件
官网:https://android.googlesource.com/platform/libnativehelper/+/refs/tags/android-8.1.0_r61
6. 代码编译:
应用下面的 patch
device/generic/car$ git df vendorsetup.sh
diff --git a/vendorsetup.sh b/vendorsetup.sh
index 1bec9aa..4e87161 100644
--- a/vendorsetup.sh
+++ b/vendorsetup.sh
@@ -20,7 +20,7 @@
# In particular, you can add lunch options with the add_lunch_combo
# function: add_lunch_combo generic-eng
-add_lunch_combo aosp_car_emu_arm-userdebug
-add_lunch_combo aosp_car_emu_arm64-userdebug
-add_lunch_combo aosp_car_emu_x86-userdebug
-add_lunch_combo aosp_car_emu_x86_64-userdebug
+add_lunch_combo aosp_car_arm-userdebug
+add_lunch_combo aosp_car_arm64-userdebug
+add_lunch_combo aosp_car_x86-userdebug
+add_lunch_combo aosp_car_x86_64-userdebug
编译命令:
source build/envsetup.sh
lunch aosp_car_x86_64-userdebug
make | tee mm.log
在编译过程中遇到的错误
报错:Android build error: ro.build.fingerprint cannot exceed 91 bytes
解决方式:
1.Edit build/tools/post_process_props.py. Change lines as follows:
PROP_NAME_MAX = 31
# PROP_VALUE_MAX = 91
PROP_VALUE_MAX = 128
2.Edit bionic/libc/include/sys/system_properties.h. Change lines as follows:
#define PROP_NAME_MAX 32
// #define PROP_VALUE_MAX 92
#define PROP_VALUE_MAX 128
3.make clean
make clean
报错:error: static_assert failed “Size mismatch.”
解决方式:
Edit frameworks/native/cmds/installd/installd_deps.h. Change lines as follows:
// constexpr size_t kPropertyValueMax = 92u;
constexpr size_t kPropertyValueMax = 128u;
转载:http://www.th7.cn/Program/Android/201701/1088115.shtml
报错:Out of memory error
解决方式:
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
./prebuilts/sdk/tools/jack-admin kill-server
./prebuilts/sdk/tools/jack-admin start-server