LineageOS編譯

準備

設備:小米5
設備代號:gemini
Android版本:8.1
PC系統: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 ~

添加到環境變量

gedit ~/.profile

輸入:

# add Android SDK platform tools to path
if [ -d "$HOME/platform-tools" ] ; then
    PATH="$HOME/platform-tools:$PATH"
fi

保存。

使改動生效:

source ~/.profile

安裝adb和fastboot

sudo apt install adb fastboot

安裝Repo和python

sudo apt install repo python

安裝依賴

安裝必要庫和工具

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

設置 git

  1. 首先安裝一些必要的環境和依賴
    sudo apt-get install build-essential fakeroot dpkg-dev
  2. 在home路徑下創建一個名爲git-rectify的路徑(路徑名不重要,可以爲其他名稱)
    mkdir ~/git-rectify
  3. 進入路徑,獲取git的源文件
    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. 進入目錄(原鏈接中這裏有錯誤,不需要解壓步驟)
cd git-2.17.1/
路徑名後面2.*是版本號,需要看一下自己的版本
7. 修改文件內容,需要修改兩個文件
vim ./debian/control # 把libcurl4-gnutls-dev 修改爲 libcurl4-openssl-dev
vim ./debian/rules # 把TEST=test整行刪除
8. 編譯和構建安裝包
sudo dpkg-buildpackage -uc -us -rfakeroot -b
9. 退回上一級目錄,安裝編譯好的安裝包
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問題。

  1. 設置 git 用戶名和郵箱
    示例如下:
    git config --global user.email “[email protected]
    git config --global user.name “Your Name”

雙引號中的 “[email protected]” 填寫您的 github 所使用的郵箱。注意格式,不要把雙引號去掉。
雙引號中的 “Your Name” 填寫您的 github 用戶名,不要把雙引號去掉。

  1. 生成 ssh 並添加到 github:
    查看~/.ssh是否存在
    如果該文件夾存在,則說明密鑰已存在,則備份刪除

2.2 生成 ssh 密鑰
在命令行中輸入
ssh-keygen -t rsa -C “your email address”
連續按3個回車(密碼默認爲空),得到 id_rsa 和 id_rsa.pub 文件,說明生成成功

三、添加密鑰到 Github
打開 Github,登錄自己的賬號後
點擊自己的頭像->settings->SSH Keys->Add SSH key
將本地 id_rsa.pub 中的內容粘貼到 Key 文本框中,隨意輸入一個 title,點擊 Add Key 即可

您可以參考官方的文檔:

https://help.github.com/articles/connecting-to-github-with-ssh/

如果您不將 ssh 添加到 github 的話,您可能會遭遇下載受限,從而導致接下來的同步源碼失敗。

清華源源代碼鏡像

過程摘錄

下載 repo 工具:

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

將~/bin放入環境變量
gedit ~/.profile
加入:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

使改動生效:

source ~/.profile

或者使用tuna的git-repo鏡像
(2)配置環境變量(在/etc/profile 或者~/.bashrc中添加如下,添加完成後執行source /etc/profile或者source ~/.bashrc使配置生效)

   export PATH=~/bin:$PATH
   export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

(3)配置本地gerrit,添加自己的信息(修改~/.gitconfig)

建立工作目錄:

 mkdir ~/LineageOS && cd ~/LineageOS

初始化倉庫:

repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-15.1

(如果已經有從github同步的lineageOS源代碼,可以從這裏直接開始)

打開.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"

同步源碼樹(以後只需執行這條命令來同步):

repo sync

異常處理

fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 101] Network is unreachable
解決方法,先單獨克隆repo
git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo
然後將git-repo裏面的repo文件複製到bin目錄,然後chmod a+x ~/bin/repo.
再在同步源碼的工作目錄新建.repo文件夾,把git-repo重命名爲repo複製到.repo目錄下:
重新初始化:
repo init -u git://github.com/CyanogenMod/android.git -b cm-12.1
同步開始
repo sync -c -j8

部分倉庫例如Lineage_framework_base同步的時候會出現bundle錯誤,這時候可以使用命令repo sync --no-clone-bundle進行同步就沒有問題了
同步源碼

repo sync -c -f -j4 --force-sync --no-clone-bundle

由於 AOSP 鏡像造成CPU/內存負載過重,清華限制了併發數量,因此建議 sync的時候併發數不宜太高,否則會出現 503 錯誤,即-j後面的數字不能太大。

repo sync -c -f -j8 --force-sync --no-clone-bundle 

下載機型配置

在項目源碼目錄下的device目錄下,新建一個目錄xiaomi
然後在xiaomi目錄下同步2個倉庫代碼

git clone https://github.com/LineageOS/android_device_xiaomi_gemini.git gemini
git clone https://github.com/LineageOS/android_device_xiaomi_msm8996-common.git msm8996

然後需要下載一個820機型的內核源碼
源碼目錄下的kernel目錄下新建目錄xiaomi,然後再xiaomi目錄下執行代碼

git clone https://github.com/LineageOS/android_kernel_xiaomi_msm8996.git msm8996

項目還需要依賴一個android_packages_resources_devicesettings 也需要同步
在源碼目錄下的packages目錄下新建目錄resources,然後在resources目錄下執行

git clone https://github.com/LineageOS/android_packages_resources_devicesettings.git -b lineage-15.1 devicesettings

拉取vendor

make vendor主要是拉取官方系統的部分必要文件用於編譯lineageos系統。
先確保手機能連adb
然後在源碼根目錄下執行 . build/envsetup.sh初始化環境
終端進入/device/xiaomi/gemini目錄下。

chmod 755 *.sh
./setup-makefiles.sh
./extract-files.sh

此時,device/vendor/xiaomi下會出現個gemini的目錄,如果沒有則將msm8996改名爲gemini。

當然這些東西都可以寫到.repo/local_manifests/local_manifests.xml裏面去,repo sync的時候會自動同步。格式差不多是這樣

<?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>

開啓緩存

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服務可以關閉,省去很多編譯錯誤:
https://blog.csdn.net/qilu0882/article/details/81328953
https://cloud.tencent.com/developer/article/1414273

開始編譯

編譯變量帶root
export WITH_SU=true
設置編譯變量 . ./build/envsetup.sh
編譯

命令
croot
brunch lineage_gemini-eng

還原代碼

瞎改代碼炸了怎麼辦?執行下面的命令還原所有修改
repo forall -c git reset --hard

遇到的錯誤

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
編譯環境下常用命令解析
https://www.cnblogs.com/vincentcc-90/p/4615258.html?tdsourcetag=s_pctim_aiomsg
ccache介紹
https://blog.csdn.net/qq_27062249/article/details/53642444
指紋支付修復參考
https://github.com/LineageOS/android_device_xiaomi_sdm845-common/commit/c8bb263e5bffa309be815f2a2cf34df393a78380

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章