编译Android源码的过程参考Android官网介绍:
1、下载Android源码的步骤:https://source.android.com/source/downloading.html
2、编译Android源码的步骤:https://source.android.com/source/building-running.html
下面就是我遇到的一些问题:
1、Compile Android Source时JDK相关的错误:
错误1:
target release 1.5 conflicts with default source release 1.7
解决办法:最好使用jdk为1.6.0.45的版本
错误2:
[out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes-full-debug.jar] Error 41
解决办法:jdk版本过低,将jdk版本升级到1.6.0.45
2、Linux下修改通过命令行安装的jdk,使用自己安装的jdk
sudo update-alternatives --install /usr/bin/jar jar /opt/java/jdk1.6.0_45/bin/jar 60
sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.6.0_45/bin/java 60
sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.6.0_45/bin/javac 60
sudo update-alternatives --install /usr/bin/javap javap /opt/java/jdk1.6.0_45/bin/javap 60
sudo update-alternatives --install /usr/bin/javadoc javadoc /opt/java/jdk1.6.0_45/bin/javadoc 60
sudo update-alternatives --config jar
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javap
sudo update-alternatives --config javadoc
当你config的时候会有如下提示:
There are 2 choices for the alternative jar (providing /usr/bin/jar).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/bin/jar 1071 auto mode
* 1 /opt/java/jdk/bin/jar 60 manual mode
2 /usr/lib/jvm/java-7-openjdk-amd64/bin/jar 1071 manual mode
Press enter to keep the current choice[*], or type selection number:
按照提示选择你所对应的路径的number即可。
3、Ubuntu 14.04 Android 4.4.2编译出错 OSError: [Errno 2] No such file or directory
错误:
[out/target/product/generic/obj/GYP/shared_intermediates/blink/CSSValueKeywords.cpp] 错误 1
解决方法:把如下所需的系统环境都安装上重新编译即可:
git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 g++-multilib
mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
如安装git,如下,其他也是一样,一个个安装即可。
sudo apt-get install git
最后如果出现如下输出,则表示安装成功:
Installed system fs image:out/target/product/generic/system.img
Target ram disk: out/target/product/generic/ramdisk.img
Target userdata fs image: out/target/product/generic/userdata.img
Installed file list: out/target/product/generic/installed-files.txt