系统为Ubuntu18.04
物理内存至少8G起步,16G以上最好,建议SWAP+RAM>=20G,太小会爆内存。
硬盘空闲空间必须大于200G,因为光源码就70G左右了。
安装依赖软件包
1
| sudo apt update && sudo apt install -y git curl python-socks libncurses5-dev xclip && git clone https://github.com/467815891a/AndroidEnv_setup.git && cd AndroidEnv_setup && sudo bash setup/android_build_env.sh && cd ..
|
设置 git用户名和邮箱
这一步其实可以省略,git clone的时候告诉远程仓库的托管服务商(如github)你的个人信息,用于认证,可以减少你被ban的几率。
示例如下:
1
| git config --global user.email "you@example.com"
|
1
| git config --global user.name "Your Name"
|
双引号中的 “you@example.com”
填写您的 github 所使用的邮箱。注意格式,不要把双引号去掉。
双引号中的 “Your Name”
填写您的 github 用户名,不要把双引号去掉。
生成 ssh 并添加到 github
1
| ssh-keygen -t ed25519 -C "you@example.com"
|
1 2 3
| eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 xclip -selection clipboard < ~/.ssh/id_ed25519.pub
|
然后将剪切板的内容粘贴到Github网站的个人设置中,详见Github官方指导
自行repo init项目(以lineageos为例)
1
| mkdir lineageos && cd lineageos && repo init -u git://github.com/LineageOS/android.git -b lineage-17.0
|
新建local_manifests(或者手动同步device tree,kernel tree,vendor tree)
1
| mkdir .repo/local_manifests
|
同步项目
因为网络环境不好,需要脚本自动化同步,失败不停重试。
在lineageos文件夹中新建repo.sh
并写入脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| cat > repo.sh << 'EOF' #!/bin/bash
ENABLE_PROXY=0
SERVER=
PORT=
PASSWD=
METHOD=chacha20-ietf-poly1305
LOCAL=1080 NAME=Shadowsocks-local PID_FILE=$HOME/shadowsocks-local.pid
check_running() { if [ -r $PID_FILE ]; then read PID < $PID_FILE if [ -d "/proc/$PID" ]; then return 0 else rm -f $PID_FILE return 1 fi else return 2 fi }
proxy_off() { if check_running; then kill -9 $PID rm -f $PID_FILE echo "Stopping $NAME success" else echo "$NAME is stopped" fi return 0 }
proxy_on() { check_running case $? in 0) echo "$NAME (pid $PID) is running..., trying to restart" proxy_off ;; 1|2) command -v ss-local >/dev/null 2>&1 || { echo >&2 "你好像没有安装ss-local";exit 1;} ;; esac ss-local -b 127.0.0.1 -s $SERVER -p $PORT -l $LOCAL -m $METHOD -k $PASSWD -f $PID_FILE if check_running; then echo "Starting $NAME success" export http_proxy="socks5://127.0.0.1:${LOCAL}" export https_proxy="socks5://127.0.0.1:${LOCAL}" echo "Setting Socks5 proxy for this shell success" return 0 else echo "Starting $NAME failed" unset https_proxy unset http_proxy echo "Unsetting Socks5 proxy for this shell success" retrun 1 fi }
repo_sync() { if [ $ENABLE_PROXY == '0' ]; then echo "==========不使用代理同步源码=========" proxy_off else if proxy_on; then echo "=========开始使用代理同步源码=========" else echo "========开启代理失败,不使用代理同步源码========" fi fi sleep 3 repo sync -j4 --no-clone-bundle --no-tags --force-sync while [ $? -ne 0 ]; do echo "======同步中断,重试中======" repo_sync done proxy_off return 0 }
case "$1" in sync) repo_sync ;; status) if [ ! -n "$https_proxy" ]; then echo "当前终端代理设置为空" else echo "当前终端代理设置为${https_proxy}" fi check_running case $? in 0) echo "$NAME (pid $PID) is running..." ;; 1|2) echo "$NAME is stopped" ;; esac ;; proxy) proxy_on ;; unproxy) proxy_off unset http_proxy unset https_proxy echo "Unsetting Socks5 proxy for this shell success" ;; *) repo_sync ;; esac EOF
|
赋予脚本执行权限并开始同步源码。
1 2
| chmod a+x repo.sh bash repo.sh
|
添加一些环境变量
1 2 3 4
| echo 'export ALLOW_MISSING_DEPENDENCIES=true' >> ~/.bashrc echo 'export USE_CCACHE=1' >> ~/.bashrc echo 'export _JAVA_OPTIONS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx8g"' >> ~/.bashrc source ~/.bashrc && export LANG=C
|
开始编译
1 2 3
| source build/envsetup.sh lunch
|