1.安裝git
sudo apt-get install git
圖片1.png
安裝成功后查看git版本
git --version
圖片2.png
出現git版本,即安裝成功。
下載git后,設置git賬戶:
git config --golbal user.email <u>“xxxx@xxx.com”</u>
git config --global user.name “xxxxx”
如下圖:
圖片3.png
2.安裝curl庫
sudo apt-get install curl
圖片4.png
3.安裝repo并設置權限
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo
圖片5.png
如上圖依次執行:
1)cd /
2)ls
3)Mkdir ~/.bin
4)curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
5)chmod a+x ~/bin/repo
4.安裝python
sudo apt-get install python
查看python版本
Python --version
圖片6.png
如果看到python版本,即安裝成功。
接下來就可以下載源碼。
1.創建Android源碼目錄
mkdir source
cd source
mkdir android_10
cd android_10
圖片7.png
我們看下目錄是否創建好,如下圖:
圖片8.png
可以看出,文件夾已創建好了。
2.設置repo的地址,這里使用的tanna源:
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
圖片9.png
3.初始化倉庫:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
圖片10.png
圖片11.png
如上截圖,可能會遇到SyntaxError:invalid syntax錯誤,這是repo和python版本不一致導致的,需要安裝python3,python3安裝好后,默認是使用python2.7版本,需要切換到python3.8版本,ubuntu系統下切換python版本的方法,步驟如下:
1).查看ubuntu下的所有python版本
ls /usr/bin/python*
圖片12.png
2).軟件注冊到update-alternatives 即更新替代列表
圖片13.png
查看update-alternatives 下的python版本
3).sudo update-alternatives --list python
圖片14.png
4).切換python版本
update-alternatives默認是auto模式,它會根據你設置的優先級,選擇優先級最高的python版本,優先級值越大,優先級越高。
sudo update-alternatives --config python
圖片15.png
這里輸入數字,即可對于應的python版本,如上截圖,我選擇2。
5).刪除python版本
如果不需要某個python版本,可以將其從update-alternatives中刪除: update-alternatives --remove python /usr/bin/python2.7
如下圖,正式切換到python3版本了。
圖片16.png
4.制定Android版本并初始化:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest b android-10.0.0_r10
圖片17.png
5.開始同步代碼源:
repo sync(ctrl+z來中斷同步,重新 repo sync來進行同步)
圖片18.png
根據提示執行如下命令:
sudo snap install git-repo
圖片19.png
補充:repo init初始化倉庫之后,仍然出現SyntaxError:invalid syntax錯誤,需要使用如下命令:python3 ~/.bin/repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
圖片20.png
制定Android版本并初始化:
python3 ~/.bin/repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-10.0.0_r10 如下截圖:
圖片21.png
同步代碼源:
python3 ~/.bin/repo sync,如下截圖:
圖片22.png
圖片23.png
從這里可以看出,正在同步源碼,是Android系統源碼的一個目錄。
圖片24.png
經過漫長等待,源碼同步完成,如下圖,該目錄下就是Android10系統源碼。
圖片25.png
有了源碼,接下來就可以使用Android stuido進行編譯系統源碼了。