200code

MacOS下用移动硬盘下载编译Android源码

下载

android细分版本号列表

制作一个大小写敏感的磁盘分区

磁盘工具 > 选中移动硬盘 > 文件 > 新建映像 > 空白映像 > 设置映像 > 存储 > 启动磁盘分区

从官网下载android源码

官方文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
repo init -u https://android.googlesource.com/platform/manifest
repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
repo sync //start download

遇到的问题1

1
2
3
ninja: build stopped: subcommand failed.
build/core/ninja.mk:148: recipe for target ‘ninja_wrapper’ failed
make: *** [ninja_wrapper] Error 1

解决:

1
2
3
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
out/host/linux-x86/bin/jack-admin kill-server
out/host/linux-x86/bin/jack-admin start-server

遇到的问题2

1
warning: gpg (GnuPG) is not available. warning: Installing it is strongly encouraged.

解决:

1
brew install gpg

使用清华源下载源码

下载repo

1
2
3
4
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

下载

1
2
3
4
5
export HTTP_PROXY=
export HTTPS_PROXY=
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.1.0_r10 // -b 后面为选择的一个[android细分版本号列表](https://source.android.com/setup/start/build-numbers) 中的一个分支号
repo sync // start download

编译

环境

1
2
3
4
5
xcode-select --install
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
export PATH=/opt/local/bin:$PATH
POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg
POSIXLY_CORRECT=1 sudo port install bison

开始编译

1
2
source build/envsetup.sh
make -j4

查看Android源码版本

1
build\core\version_defaults.mk //搜索该文件中的 PLATFORM_VERSION值