はじめに
ドキュメントがあるので、基本的にはこちらを見たほうがいいと思います
この記事は忘備録です...
https://source.android.com/docs/setup/start/initializing?hl=ja
https://source.android.com/docs/setup/build/building?hl=ja
0.環境
ビルドした環境は以下になります
$cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
...
$ uname -m
x86_64
1.wslのメモリの割り当てを変更する
aospは非常に巨大なプロジェクトのため、できるだけ多くのメモリを割り当てることをお勧めします
[wsl2]
memory=32GB
2.必要なパッケージをインストールする
sudo apt update
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
3.作業ディレクトリの作成/初期化
mkdir `WORKING_DIRECTORY`
cd `WORKING_DIRECTORY`
repo init -u https://android.googlesource.com/platform/manifest -b `BRANCH`
nproc --all
repo sync -c -j`n` # `n` には nproc --all で出力されたスレッド数を入力する
利用可能なbranchの一覧はこちらにあります
https://source.android.com/docs/setup/reference/build-numbers?hl=ja#source-code-tags-and-builds
branchはここではandroid-11.0.0_r48
としました
理由として、android7をビルドしようとすると、環境構築がうまくいかずjavaのビルドエラーがでたこと、またandroid10はarm、arm64のアプリをx86上で動かすことが難しかったことが挙げられます
(android10以降では確かプロジェクト内にjavaが含まれていて環境構築でつまづきにくくなっていたはずです...)
repo sync
は時間がかかるので気楽に待ちましょう
寝ている間などにすべての環境構築を終わらせたい場合は以下のようなシェルスクリプトを組んでください(4のステップの内容も含まれています)
yes | repo sync -c -j`n`
. build/envsetup.sh
lunch aosp_x86_64-eng
m
4.ビルド
非常に時間がかかるので気長に待ちましょう
ここでタスクマネージャーのパフォーマンスタブを開くとCPUとメモリがフルで動いていて面白いと思います
. build/envsetup.sh
lunch aosp_x86_64-eng
m
5.エミュレーターの起動
. build/envsetup.sh
lunch aosp_x86_64-eng
emulator -gpu swiftshader_indirect -memory 4096
-gpu swiftshader_indirect
はこちらの環境だとないとうまく動きませんでした
6.最後に
enjoy!
(ソースコード検索はAndroid Code Searchを使うといいと思います)
https://cs.android.com/?hl=ja