LineageOS编译
目錄
- 準(zhǔn)備
- 下載并解壓SDK
- 安裝adb和fastboot
- 安裝Repo和python
- 安裝依賴
- 設(shè)置 git
- 清華源源代碼鏡像
- 過(guò)程摘錄
- 異常處理
- 下載機(jī)型配置
- 拉取vendor
- 開(kāi)啟緩存
- 開(kāi)始編譯
- 還原代碼
- 遇到的錯(cuò)誤
- error: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated.
- buildinfo: clear-sign failed: No secret key
- 附錄:
準(zhǔn)備
設(shè)備:小米5
設(shè)備代號(hào):gemini
Android版本:8.1
PC系統(tǒng):Ubuntu18.04
下載并解壓SDK
sdk中包含fastboot和adb
下載
wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip解壓
unzip platform-tools-latest-linux.zip -d ~添加到環(huán)境變量
gedit ~/.profile輸入:
# add Android SDK platform tools to path if [ -d "$HOME/platform-tools" ] ; thenPATH="$HOME/platform-tools:$PATH" fi保存。
使改動(dòng)生效:
source ~/.profile安裝adb和fastboot
sudo apt install adb fastboot安裝Repo和python
sudo apt install repo python安裝依賴
安裝必要庫(kù)和工具
sudo apt-get install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev安裝openjdk-8-jdk
sudo apt install -y openjdk-8-jdk設(shè)置 git
sudo apt-get install build-essential fakeroot dpkg-dev
mkdir ~/git-rectify
cd ~/git-rectify
sudo sed -i – ‘s/#deb-src/deb-src/g’ /etc/apt/sources.list && sudo sed -i –
‘s/# deb-src/deb-src/g’ /etc/apt/sources.list
sudo apt-get update
apt-get source git
4. 安裝依賴
sudo apt-get build-dep git
5. 安裝libcurl的依賴文件
sudo apt-get install libcurl4-openssl-dev
6. 進(jìn)入目錄(原鏈接中這里有錯(cuò)誤,不需要解壓步驟)
cd git-2.17.1/
路徑名后面2.*是版本號(hào),需要看一下自己的版本
7. 修改文件內(nèi)容,需要修改兩個(gè)文件
vim ./debian/control # 把libcurl4-gnutls-dev 修改為 libcurl4-openssl-dev
vim ./debian/rules # 把TEST=test整行刪除
8. 編譯和構(gòu)建安裝包
sudo dpkg-buildpackage -uc -us -rfakeroot -b
9. 退回上一級(jí)目錄,安裝編譯好的安裝包
cd …
sudo dpkg -i git_2.17.1-1ubuntu0.4_amd64.deb
完成以上步驟即可解決error: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated問(wèn)題。
示例如下:
git config --global user.email “you@example.com”
git config --global user.name “Your Name”
雙引號(hào)中的 “you@example.com” 填寫(xiě)您的 github 所使用的郵箱。注意格式,不要把雙引號(hào)去掉。
雙引號(hào)中的 “Your Name” 填寫(xiě)您的 github 用戶名,不要把雙引號(hào)去掉。
查看~/.ssh是否存在
如果該文件夾存在,則說(shuō)明密鑰已存在,則備份刪除
2.2 生成 ssh 密鑰
在命令行中輸入
ssh-keygen -t rsa -C “your email address”
連續(xù)按3個(gè)回車(密碼默認(rèn)為空),得到 id_rsa 和 id_rsa.pub 文件,說(shuō)明生成成功
三、添加密鑰到 Github
打開(kāi) Github,登錄自己的賬號(hào)后
點(diǎn)擊自己的頭像->settings->SSH Keys->Add SSH key
將本地 id_rsa.pub 中的內(nèi)容粘貼到 Key 文本框中,隨意輸入一個(gè) title,點(diǎn)擊 Add Key 即可
您可以參考官方的文檔:
https://help.github.com/articles/connecting-to-github-with-ssh/
如果您不將 ssh 添加到 github 的話,您可能會(huì)遭遇下載受限,從而導(dǎo)致接下來(lái)的同步源碼失敗。
清華源源代碼鏡像
過(guò)程摘錄
下載 repo 工具:
mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo將~/bin放入環(huán)境變量
gedit ~/.profile
加入:
使改動(dòng)生效:
source ~/.profile或者使用tuna的git-repo鏡像
(2)配置環(huán)境變量(在/etc/profile 或者~/.bashrc中添加如下,添加完成后執(zhí)行source /etc/profile或者source ~/.bashrc使配置生效)
(3)配置本地gerrit,添加自己的信息(修改~/.gitconfig)
建立工作目錄:
mkdir ~/LineageOS && cd ~/LineageOS初始化倉(cāng)庫(kù):
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-15.1(如果已經(jīng)有從github同步的lineageOS源代碼,可以從這里直接開(kāi)始)
打開(kāi).repo/manifest.xml,將
<remote name="github"fetch=".."review="review.lineageos.org" />改成
<remote name="github"fetch="https://github.com/" /><remote name="lineage"fetch="https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/"review="review.lineageos.org" />將
<remote name="aosp"fetch="https://android.googlesource.com"改成
<remote name="aosp"fetch="https://aosp.tuna.tsinghua.edu.cn"將
<default revision="..."remote="github"改成
<default revision="..."remote="lineage"同步源碼樹(shù)(以后只需執(zhí)行這條命令來(lái)同步):
repo sync異常處理
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 101] Network is unreachable
解決方法,先單獨(dú)克隆repo
git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo
然后將git-repo里面的repo文件復(fù)制到bin目錄,然后chmod a+x ~/bin/repo.
再在同步源碼的工作目錄新建.repo文件夾,把git-repo重命名為repo復(fù)制到.repo目錄下:
重新初始化:
repo init -u git://github.com/CyanogenMod/android.git -b cm-12.1
同步開(kāi)始
repo sync -c -j8
部分倉(cāng)庫(kù)例如Lineage_framework_base同步的時(shí)候會(huì)出現(xiàn)bundle錯(cuò)誤,這時(shí)候可以使用命令repo sync --no-clone-bundle進(jìn)行同步就沒(méi)有問(wèn)題了
同步源碼
repo sync -c -f -j4 --force-sync --no-clone-bundle
由于 AOSP 鏡像造成CPU/內(nèi)存負(fù)載過(guò)重,清華限制了并發(fā)數(shù)量,因此建議 sync的時(shí)候并發(fā)數(shù)不宜太高,否則會(huì)出現(xiàn) 503 錯(cuò)誤,即-j后面的數(shù)字不能太大。
repo sync -c -f -j8 --force-sync --no-clone-bundle下載機(jī)型配置
在項(xiàng)目源碼目錄下的device目錄下,新建一個(gè)目錄xiaomi
然后在xiaomi目錄下同步2個(gè)倉(cāng)庫(kù)代碼
然后需要下載一個(gè)820機(jī)型的內(nèi)核源碼
源碼目錄下的kernel目錄下新建目錄xiaomi,然后再xiaomi目錄下執(zhí)行代碼
項(xiàng)目還需要依賴一個(gè)android_packages_resources_devicesettings 也需要同步
在源碼目錄下的packages目錄下新建目錄resources,然后在resources目錄下執(zhí)行
拉取vendor
make vendor主要是拉取官方系統(tǒng)的部分必要文件用于編譯lineageos系統(tǒng)。
先確保手機(jī)能連adb
然后在源碼根目錄下執(zhí)行 . build/envsetup.sh初始化環(huán)境
終端進(jìn)入/device/xiaomi/gemini目錄下。
此時(shí),device/vendor/xiaomi下會(huì)出現(xiàn)個(gè)gemini的目錄,如果沒(méi)有則將msm8996改名為gemini。
當(dāng)然這些東西都可以寫(xiě)到.repo/local_manifests/local_manifests.xml里面去,repo sync的時(shí)候會(huì)自動(dòng)同步。格式差不多是這樣
<?xml version="1.0" encoding="UTF-8"?> <manifest><remote name="LineageOS"fetch="https://github.com"review="review.lineageos.org" /><project name="LineageOS/android_device_xiaomi_gemini" path="device/xiaomi/gemini" remote="LineageOS" revision="lineage-15.1" /><project name="LineageOS/android_device_xiaomi_msm8996-common" path="device/xiaomi/msm8996" remote="LineageOS" revision="lineage-15.1" /><project name="LineageOS/android_kernel_xiaomi_msm8996" path="kernel/xiaomi/msm8996" remote="LineageOS" revision="lineage-15.1" /><project name="LineageOS/android_packages_resources_devicesettings.git" path="packages/resources/devicesettings" remote="LineageOS" revision="lineage-15.1" /> </manifest>開(kāi)啟緩存
apt install ccache
export USE_CCACHE=1
ccache -M 50G
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
jack服務(wù)可以關(guān)閉,省去很多編譯錯(cuò)誤:
https://blog.csdn.net/qilu0882/article/details/81328953
https://cloud.tencent.com/developer/article/1414273
開(kāi)始編譯
編譯變量帶root
export WITH_SU=true
設(shè)置編譯變量 . ./build/envsetup.sh
編譯
命令
croot
brunch lineage_gemini-eng
還原代碼
瞎改代碼炸了怎么辦?執(zhí)行下面的命令還原所有修改
repo forall -c git reset --hard
遇到的錯(cuò)誤
error: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated.
https://zhuanlan.zhihu.com/p/53961303
https://blog.csdn.net/voyagflyer/article/details/72773503
buildinfo: clear-sign failed: No secret key
https://codeday.me/bug/20181108/358289.html
附錄:
LineageOS 官方編譯教程
https://wiki.lineageos.org/devices/kiwi/build
編譯環(huán)境下常用命令解析
https://www.cnblogs.com/vincentcc-90/p/4615258.html?tdsourcetag=s_pctim_aiomsg
ccache介紹
https://blog.csdn.net/qq_27062249/article/details/53642444
指紋支付修復(fù)參考
https://github.com/LineageOS/android_device_xiaomi_sdm845-common/commit/c8bb263e5bffa309be815f2a2cf34df393a78380
總結(jié)
以上是生活随笔為你收集整理的LineageOS编译的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux pwn练习0x02
- 下一篇: PowerShell脚本遇到的问题汇总