0. introduce
系统 Ubuntu16.04
/etc/apt/sources.list
'
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
# deb https://download.docker.com/linux/ubuntu trusty main
# deb-src https://download.docker.com/linux/ubuntu trusty main
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
# deb-src [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
'
1. ready
下载指定版本的android源码(此处是R)
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'
./repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-11.0.0_r17
./repo sync
出现错误的话,一直执行./repo sync
如果出现如下错误:
error: Cannot checkout platform/cts: ManifestInvalidRevisionError: revision refs/tags/android-11.0.0_r17 in platform/cts not found
error: in `sync -c platform/cts`: revision refs/tags/android-11.0.0_r17 in platform/cts not found
请使用
./repo sync -c platform/cts
有个小技巧,循环下载: repo_sync_project.sh project.list
# project.list中主要是那些不容易下载下来的project
#! /bin/bash
CNT=1
while [ 1 ]
do
echo $CNT
cat $1|while read line
do
echo "packing $line"
./repo sync -c $line
done
let CNT+=1
done
或者
while [ 1 ]
do
./repo sync
done
2. compile
. build/envsetup.sh
lunch aosp_x86-eng
make -j16
3. 在Intellij IDEA中查看android源码
. build/envsetup.sh
make idegen
sudo development/tools/idegen/idegen.sh
// 可能出现如下错误(java版本过多导致)
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
// 解决办法是
sudo update-alternatives --config java
选择对应的java版本
// 最终生成
android.iml android.ipr
// 在Intellij IDEA中打开android.ipr
// 就可以完美的查看调用关系.