Android 4.0.1 源码编译过程
一、环境准备
系统:ubuntu 14.04 64bit
Java: 1.6.0_45
安装需要的库:
sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
libgl1-mesa-dev libxml2-utils xsltproc unzip
二、下载源代码
安装 Repo
创建 bin 目录
$ mkdir ~/bin
$ PATH=~/bin:$PATH
下载 rope tool
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
初始化一个 Repo client
- 创建目录
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
- 配置git
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
- 初始化 repo
repo init -u https://android.googlesource.com/platform/manifest
-b android-4.0.1_r1
- 创建目录
下载 Android 源码
$ repo sync
三、编译源码
初始化环境
$ source build/envsetup.sh
选择target
$ lunch
选择默认的full-eng就好,这个表示运行在模拟器的编译方式
编译源码
$ make -j4 (可以根据内核个数选用不同的编译命令)
错误处理(在编译源码时会出现不少错误)
错误详情:
out/host/linux-x86/obj/lib/libOpenglRender.so
解决办法:
安装32位的libX11库, sudo apt-get install libx11-dev:i386
错误详情:
out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/emulator_renderer
解决办法:
vi development/tools/emulator/opengl/host/renderer/Android.mk
Add new entry 'LOCAL_LDLIBS += -lX11' after line 6 as shown:
LOCAL_SRC_FILES := main.cpp
LOCAL_CFLAGS += -O0 -g
LOCAL_LDLIBS += -lX11
错误详情:
out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o
解决办法:
vim /build/core/combo/HOST_linux-x86.mk
将以下语句
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
修改为
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
错误详情:
out/host/linux-x86/obj/lib/libGLES_CM_translator.so
解决办法:
sudo apt-get installibgl1-mesa-glx:i386
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
错误详情:
out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/AaptAssets.o
解决办法:
vi frameworks/base/tools/aapt/Android.mk
Add '-fpermissive' to line 31:
LOCAL_CFLAGS += -Wno-format-y2k -fpermissive
错误详情:
out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/AssetManager.o
解决办法:
vi frameworks/base/libs/utils/Android.mk
Add '-fpermissive' to line 64:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive
错误详情:
out/host/linux-x86/obj/EXECUTABLES/grxmlcompile_intermediates/grxmlcompile.o
解决办法:
cd external/srec
wget "https://github.com/CyanogenMod/android_external_srec/commit/4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff"
patch -p1 < 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
rm -f 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
cd ../..
错误详情:
out/host/linux-x86/obj/EXECUTABLES/emugen_intermediates/main.o
解决办法:
vi development/tools/emulator/opengl/host/tools/emugen/main.cpp
Add '#include <getopt.h>' to list of includes:
#include <getopt.h>
错误详情:
out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o
解决办法:
vi external/oprofile/libpp/format_output.h
Remove 'mutable' from 'mutable counts_t & counts;' on line 94:
counts_t & counts;
错误详情:
out/host/linux-x86/obj/STATIC_LIBRARIES/libOpenglCodecCommon_intermediates/GLSharedGroup.o
解决办法:
vi development/tools/emulator/opengl/Android.mk
Add '-fpermissive' to line 25:
EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -fpermissive
错误详情:
out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs.o
解决办法:
vi frameworks/compile/slang/Android.mk
Remove '-Werror' from line 22:
local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter
错误详情:
out/host/linux-x86/obj/STATIC_LIBRARIES/libRS_intermediates/rsFont.o
解决办法:
vi frameworks/base/libs/rs/Android.mk
Add '-fpermissive' to line 183
LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fpermissive
错误详情:
out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o
解决办法:
vi external/mesa3d/src/glsl/linker.cpp
Add '#include <stddef.h>' to list of includes as shown:
#include <climits>
#include <stddef.h>
#include <pixelflinger2/pixelflinger2_interface.h>
错误详情:
out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o
解决办法:
vi external/gtest/src/Android.mk
Add '-fpermissive' to lines 52 and 70 (both lines contain same info)
LOCAL_CFLAGS += -O0 -fpermissive
vi external/gtest/include/gtest/internal/gtest-param-util.h
Add '#include <stddef.h>' to list of includes as shown:
#include <vector>
#include <cstddef>
#include <gtest/internal/gtest-port.h>
错误详情:
out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader
解决办法:
vi external/llvm/llvm-host-build.mk +
LOCAL_LDLIBS := -lpthread -ldl错误详情:
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMJIT_intermediates/Intercept.o
解决办法:
vim external/llvm/lib/ExecutionEngine/JIT/Intercept.cpp
add head files:
#define _LARGEFILE64_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
运行
可以直接执行命令:$ emulator来运行
如果找不到emulator命令需要按照下面的顺序再配置下环境:
$ source build/envsetup.sh
$ lunch full-eng
$ emulator