http://blog.csdn.net/huaiyiheyuan/article/details/52069122
源码编译 :
一 、JDK环境准备
在编译 android-6.0.1_r1 一直提示要安装openjdk-7
没办法 先按提示来吧 ,如果是7.0,下载openjdk-8-jdk
terminal 输入 :
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk
选择JDK版本
sudo update-alternatives --config java
sudo update-alternatives --config javac
需要下载JDK6按照这个教程
https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04
二、源码下载、
1、 按照正常的方法,前提是你得有个梯子,下载也要很久,如果没环境的,可以去科大源 、清华源(感谢良心工程)下载, 我下载的是压缩包
2、在home路径下 下面不需要代理
Make sure you have a bin/ directory in your home directory and that it is included in your path:
$ mkdir ~/bin
$ PATH=~/bin:$PATH
Download the Repo tool and ensure that it is executable:
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
然后是
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-7.1.1_r27
repo sync
或者下载
aosp-latest.tar
按照 2就好了
三、编译
1、环境准备
由于不知道里面的道道,索性全部安装
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
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 libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
2、开始编译:
make clobber
source build/envsetup.sh
lunch aosp_arm-eng
make -j8
三 .编译的错误
1编译的android7.1.1
现在用下面方法解决了
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
参考:
http://stackoverflow.com/questions/35579646/android-source-code-compile-error-try-increasing-heap-size-with-java-option
2、编译android6.x
之前编译android6.x时, 用这个方法虽然能解决一时的错误,但是后面接下来的错误我一直没找到方法解决,后面不得不全部删了 重新拉出代码
Ensure Jack server is installed and started Jack server already
installed in "/home/jon/.jack-server"Server is already running
就是引起的这个错误一直没解决,不得不重来
然后用下面方法解决
方法一:
在编译命令之前,修改prebuilts/sdk/tools/jack-admin文件,找到文件中的这一行:
JACK_SERVER_COMMAND=“java -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -cp $LAUNCHER_JAR
L
A
U
N
C
H
E
R
N
A
M
E
"
然
后
在
该
行
添
加
−
X
m
x
4096
m
,
如
:
J
A
C
K
S
E
R
V
E
R
C
O
M
M
A
N
D
=
"
j
a
v
a
−
D
j
a
v
a
.
i
o
.
t
m
p
d
i
r
=
LAUNCHER_NAME" 然后在该行添加-Xmx4096m,如: JACK_SERVER_COMMAND="java -Djava.io.tmpdir=
LAUNCHERNAME"然后在该行添加−Xmx4096m,如:JACKSERVERCOMMAND="java−Djava.io.tmpdir=TMPDIR $JACK_SERVER_VM_ARGUMENTS -Xmx4096m -cp $LAUNCHER_JAR $LAUNCHER_NAME”
参考:
http://stackoverflow.com/questions/35579646/android-source-code-compile-error-try-increasing-heap-size-with-java-option
问题二
out/host/linux- x86/obj32/SHARED_LIBRARIES/libartd_intermediates/arch/x86/quick_entrypoints_x86.o:function art_quick_deoptimize: error: unsupported reloc 43
clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:51: recipe for target ‘out/host/linux-x86/obj32/lib/libartd.so’ failed
make: *** [out/host/linux-x86/obj32/lib/libartd.so] Error 1
clang编译器导致的问题,目前可行的修改方法时在art/build/Android.common_build.mk ,中将host 默认编辑器使用clang关掉,找到WITHOUT_HOST_CLANG
关闭clang即可
# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := false
endif
:参考
http://blog.csdn.net/u011444472/article/details/51463074
然后再执行 make -j8
编译完成:
2、运行
在编译完成之后,就可以通过以下命令运行Android虚拟机了,命令如下:
source build/envsetup.sh
lunch
(选择编译时设置的目标版本,比如这里了我选择的是1 lunch aosp_arm-eng)
emulator
然后就可以看到7.0的模拟器界面了
四、Android Studio导入源码
$ source build/envsetup.sh
$ mmm development/tools/idegen/
会在out/host/linux-x86/frameworks/目录下生成了idegen.jar文件
$ development/tools/idegen/idegen.sh
会在根目录下生成
android.iml和android.ipr这两个文件,这两个文件是Android Studio的工程配置文件
接着用Android Studio导入源码,打开android.iml,<excludeFolder 平行标签添加
右键 -> open_model setting
<excludeFolder url="file://$MODULE_DIR$/.repo" />
<excludeFolder url="file://$MODULE_DIR$/abi" />
<excludeFolder url="file://$MODULE_DIR$/art" />
<excludeFolder url="file://$MODULE_DIR$/bionic" />
<excludeFolder url="file://$MODULE_DIR$/bootable" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/compatibility" />
<excludeFolder url="file://$MODULE_DIR$/cts" />
<excludeFolder url="file://$MODULE_DIR$/dalvik" />
<excludeFolder url="file://$MODULE_DIR$/developers" />
<excludeFolder url="file://$MODULE_DIR$/development" />
<excludeFolder url="file://$MODULE_DIR$/device" />
<excludeFolder url="file://$MODULE_DIR$/docs" />
<excludeFolder url="file://$MODULE_DIR$/external" />
<excludeFolder url="file://$MODULE_DIR$/external/bluetooth" />
<excludeFolder url="file://$MODULE_DIR$/external/chromium" />
<excludeFolder url="file://$MODULE_DIR$/external/emma" />
<excludeFolder url="file://$MODULE_DIR$/external/icu4c" />
<excludeFolder url="file://$MODULE_DIR$/external/jdiff" />
<excludeFolder url="file://$MODULE_DIR$/external/webkit" />
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs" />
<excludeFolder url="file://$MODULE_DIR$/hardware" />
<excludeFolder url="file://$MODULE_DIR$/kernel" />
<excludeFolder url="file://$MODULE_DIR$/libcore" />
<excludeFolder url="file://$MODULE_DIR$/libnativehelper" />
<excludeFolder url="file://$MODULE_DIR$/ndk" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/out/eclipse" />
<excludeFolder url="file://$MODULE_DIR$/out/host" />
<excludeFolder url="file://$MODULE_DIR$/out/target/common/docs" />
<excludeFolder url="file://$MODULE_DIR$/out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates" />
<excludeFolder url="file://$MODULE_DIR$/out/target/product" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/pdk" />
<excludeFolder url="file://$MODULE_DIR$/platform_testing" />
<excludeFolder url="file://$MODULE_DIR$/prebuilt" />
<excludeFolder url="file://$MODULE_DIR$/prebuilts" />
<excludeFolder url="file://$MODULE_DIR$/sdk" />
<excludeFolder url="file://$MODULE_DIR$/system" />
<excludeFolder url="file://$MODULE_DIR$/test" />
<excludeFolder url="file://$MODULE_DIR$/toolchain" />
<excludeFolder url="file://$MODULE_DIR$/tools" />
:然后open android.ipr
五、调试源码
http://blog.csdn.net/yanbober/article/details/48846331
http://blog.csdn.net/songjinshi/article/details/53020549
http://ronubo.blogspot.com/2016/01/debugging-aosp-platform-code-with.html
Android其他版本编译
1、有时候 GUU MAKE版本不合适,就需要下载安装了下面是下载4.1的方法
cd /tmp
wget http://ftp.gnu.org/gnu/make/make-4.1.tar.gz
tar xvf make-4.1.tar.gz
./configure
make
sudo make install
rm -rf make-4.1.tar.gz make-4.1
可以用http://ftp.gnu.org/gnu/make 选择你需要的
http://stackoverflow.com/questions/31912233/how-to-update-make-3-81-linux
本文参考:
https://source.android.com/setup/downloading
https://source.android.com/source/index.html
http://www.jianshu.com/p/367f0886e62b
http://www.jianshu.com/p/fb16fa459acf