Android 源码编译环境配置及问题分析
1 安装Ubuntu 系统,
Android 代码的版本跟Ubuntu 的版本最好也要匹配,不要合最新的Ubuntu 18.4 去编译Android 5.0 代码,建议 Android 5.0,使用Ubuntu 16.4 , 要求64位;
2 安装JDK
在Android 5.0 需要使用JDK 1.7, 不能使用openjdk
3 配置JAVA 环境变量
sudo gedit /etc/profile 或者 sudo vim /etc/profile
export JAVA_HOME=/home/swden/java/jdk1.8.0_144
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
source /etc/profile
4 配置需要的环境
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install lib32z-dev ccache
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
或者一次全部安装
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386 && sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib && sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 && sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev && sudo apt-get install git-core gnupg flex bison gperf build-essential && sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib && sudo apt-get install libc6-dev-i386 && sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev && sudo apt-get install lib32z-dev ccache && sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
5 解压代码
导入环境
source build/envsetup.sh
lunch
选择自己要编译的项目
开始编译,并且把日志输出到log.txt
make -j6 2>&1 | tee log.txt
错误记录
target thumb C++: v8_tools_gyp_v8_base_gyp <=
external/chromium_org/v8/src/builtins.cc target thumb C++:
v8_tools_gyp_v8_base_gyp <=
external/chromium_org/v8/src/cached-powers.cc target thumb C++:
v8_tools_gyp_v8_base_gyp <= external/chromium_org/v8/src/checks.cc
target thumb C++: v8_tools_gyp_v8_base_gyp <=
external/chromium_org/v8/src/code-factory.cc clang++: error: unable to
execute command: Killed clang++: error: assembler command failed due
to signal (use -v to see invocation) clang version 3.5 Target:
i386--linux-gnu Thread model: posix clang++: note: diagnostic msg:
PLEASE submit a bug report to http://llvm.org/bugs/ and include the
crash backtrace, preprocessed source, and associated run script.
clang++: note: diagnostic msg:
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed
source(s) and associated run script(s) are located at: clang++: note:
diagnostic msg: /tmp/android_system_OsConstants-c37b42.cpp clang++:
note: diagnostic msg: /tmp/android_system_OsConstants-c37b42.sh
clang++: note: diagnostic msg:
******************** make: *** [out/host/linux-x86/obj32/SHARED_LIBRARIES/libjavacore_intermediates/luni/src/main/native/android_system_OsConstants.o]
Error 254 make: *** Waiting for unfinished jobs....
make failed to build some targets (02:21:58 (hh:mm:ss))
由于系统空间不足,内存太小,把虚拟机内存放到6G,200G硬盘