Android源代码下载与编译 - 2020

使用https://mirrors.tuna.tsinghua.edu.cn/help/AOSP 进行下载Android源码

1.下载repo工具

到清华mirror下载repo

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo

设置更新源:

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

2.下载Android

因为Android的源码越来越大,repo sync失败的概率也越来越高。
所以我们可以避开使用repo sync的方式,而采用下载预下载包的方式来实现:

wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包
tar xf aosp-latest.tar
cd AOSP   # 解压得到的 AOSP 工程目录
# 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
#查看分支 
cd .repo/manifests 
git branch -a
#选择需要同步的版本
repo init -b android-9.0.0_r55
repo sync # 正常同步一遍即可得到完整目录
# 或 
repo sync -l #仅checkout代码
#加载具体模块
repo sync platform/prebuilts/clang/host/darwin-x86

3.编译代码

配置编译环境
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
编译执行
 . build/envsetup.sh
 lunch #选择编译版本
 make -j16 #编译 
 #make -j4 2>&1 | tee build.log   保存编译记录
 make clobber #清除
启动模拟器

4.下载和编译Android内核源码

git clone https://aosp.tuna.tsinghua.edu.cn/kernel/msm.git
cd msm
git branch -a
git checkout remotes/origin/android-goldfish-3.4

5.使用Android Studio 查看源代码

mmm development/tools/idegen/
./development/tools/idegen/idegen.sh

Android Studio 打开android.irp

参考

http://blog.hsujee.com/2018/07/03/Android/Common/2018-07-03-Android源码和内核下载编译流程/<br/>
https://yq.aliyun.com/articles/695410
https://blog.csdn.net/su749520/article/details/82800050
https://blog.csdn.net/qq_34738528/article/details/99621444
https://blog.csdn.net/qq_35904259/article/details/61200880
https://blog.csdn.net/github_19529589/article/details/80901130


Frankchey
0 声望0 粉丝