编译Android系统源码

step1.#打开Android源码目录
cd home/user/android_src
step2.#source命令即逐句执行脚本。加载编译环境和编译指令
source./build/envsetup.sh
step3.#选择编译分支
lunch
full-eng
step4.#开始编译 --jn,n的大小和cpu核数有关,一般取核数的2倍
make j4

编译过程中遇到的若干问题:
1.Checking API: checkpublicapi-last

prebuilts/sdk/api/23.txt:8: error 9: Removed public constructor android.Manifest.permission.Manifest.permission()

...

******************************

You have tried to change the API from what has been previously released in

an SDK.  Please fix the errors listed above.

******************************

build/core/tasks/apicheck.mk:46: recipe for target 'out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp' failed

make: *** [out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp] Error 38

#### make failed to build some targets (01:10 (mm:ss)) ####

解决过程:网上说是因为api的版本变化了,所以导致编译失败,通过make update-api命令同步当前api版本,依然没有解决掉问题.不过确实是由于api版本的问题,android6.0只能由openjdk7来编译,我本地使用的是sunjdk8,本地的openjdk7是残缺的,所以我卸载原来的openjdk7,并重新下载安装了openjdk7,并且进行配置之后,最后再次执行make update-api同步api,编译成功!
2.明明配置了JDK,却还是找不到JDK: could not find jdk tools.jar, please install JDKX,应当检查jdk环境配置,通过source /etc/profile命令使环境变量生效
3、/bin/bash: bison: command not found2Yacc: aidl <= frameworks/base/tools/aidl/aidl_language_y.y3bison -d -o out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cppframeworks/base/tools/aidl/aidl_language_y.y4/bin/bash: bison: command not found5make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Error127
分析:因为缺少bison,所以需要安装bison
解决方案:apt-get install bison
4、/bin/bash: flex: command not found...
同理,解决方案:apt-get install flex
5、如遇到缺少 sys/cdefs.h 的情况,输入以下命令安装标c库
 apt-get install  build-essential libc6-dev libc6-dev-i386
6、如遇到缺少 bits/c++config.h的情况,输入以下命令安装gcc编译相关库
sudo apt-get install gcc-multilib g++-multilib
如果上面的安装最新版失败了,也可以尝试下面的版本
sudo  apt-get  install   gcc-4.7-multilib     g++-4.7-multilib

sudo apt-get install gcc-4.8-multilib g++-4.8-multilib
7、编译错误之: warning: "_FORTIFY_SOURCE" redefined
分析:由于 android 在编译的过程中,使用了Werror 的选项,那么任何warning 都会当作错误来处理。在编译 android 4.0 (IceCreamSandwith) 的时候,由于使用的编译器中可能内置了 _FORITY_SOUCE 这个宏,在编译 android 代码的时候,会发生错误。
解决方案:vim build/core/comb/HOST_linux_x86.mk 文件中找到下面这句:
56行:HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
替换成为:
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

8、/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status...
分析:编译的时候出现"/usr/bin/ld: cannot find -lz"错误,需要安装zlib-dev这个包,在线安装命令为:apt-get install zlib1g-dev。
解决方案:apt-get install lib32z1-dev /lib64z1-dev
如果还是不能解决,尝试:apt-get install zlib1g-dev
or
apt-get install zlib*
9、host Executable: a3dconvert (out/host/linux-x86/obj/EXECUTABLES/a3dconvert_intermediates/a3dconvert) 2/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.5.4/libstdc++.so when searchingfor-lstdc++ 3/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.5.4/libstdc++.a when searchingfor-lstdc++ 4/usr/bin/ld: can not find-lstdc++ 5/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.5.4/libgcc_s.so when searchingfor-lgcc_s 6/usr/bin/ld: can not find-lgcc_s 7/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.5.4/libgcc.a when searchingfor-lgcc 8/usr/bin/ld: can not find-lgcc 9collect2:ldreturned1 exit status10make: *** [out/host/linux-x86/obj/EXECUTABLES/a3dconvert_intermediates/a3dconvert] Error
分析:缺少g++-multilib库,安装即可: apt-get install g++-multilib
解决方案:$ sudo apt-get install g++-multilib g++-4.5-multilib
10、dalvik/vm/native/dalvik_system_Zygote.cpp:199:19: error: aggregate ‘setrlimitsFromArray(ArrayObject*)::rlimit rlim’ has incomplete type and cannot be defined
struct rlimit rlim;
                   ^
dalvik/vm/native/dalvik_system_Zygote.cpp:222:43: error: ‘setrlimit’ was not declared in this scope
err = setrlimit(contents[0], &rlim);
分析&解决:I’m not sure if it’s due to a recent Arch Linux change or what, but it seems the fix is simply to add “#include ” to dalvik/vm/native/dalvik_system_Zygote.cpp.
11、host Executable: adb (out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb)
/usr/bin/ld: cannot find -lncurses
解决方案:
 apt-get install libncurses5-dev
12、注意:/usr/bin/ld: cannot find -lncurses
/usr/bin/ld: cannot find -lz
/usr/bin/ld: cannot find -lxx
表示是一个动态库libxx.so,
①通过apt-file search libXX.so查找所有版本含有libXX.so文件的目录
选择和缺少的文件相一致的版本
\\或者可以先用apt-cache search libxx查找有哪些可以下载的版本
②选择合适的版本用apt-get install 进行下载(通常请选择带dev的包安装)

你可能感兴趣的:(编译Android系统源码)