Hsüan's Blog

2023-10-22

Build LineageOS (for Nexus 5)

基本上是參照此篇

  • 先確保 adb, fastboot 都可以使用

    • 若是使用 Windows + wsl2 可先參照此篇進行設定
  • 將 Nexus 5 手機開啟 dev debug 並且連接好,確定 adb devices 看得到

  • 將 linux 灌好需要的軟體

    apt install android-sdk-platform-tools
    
    # basic
    apt install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git git-lfs gnupg gperf imagemagick lib32readline-dev lib32z1-dev libelf-dev liblz4-tool libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev
    
    # 我使用的是 ubuntu 22.04,要再裝
    apt install lib32ncurses5-dev libncurses5 libncurses5-dev
    
    # java 因為 Nexus 是裝 LineageOS 14.1,所以要安裝
    apt install openjdk-8-jdk
    # 記得要在 /etc/java-8-openjdk/security/java.security 檔案的 jdk.tls.disabledAlgorithms 裡移除 TLSv1 跟 TLSv1.1
    
    # python
    apt install python-is-python3 python3-virtualenv
    
    # 因為 Nexus 是裝 LineageOS 14.1,但是 Ubuntu 22.04 又沒有 python-is-python2 了,所以要
    apt install python2 python2-setuptools-whl python2-pip-whl
    virtualenv --python=python2 ~/.lineage_venv
  • 準備同步 LineageOS 的原始檔案

    mkdir -p ~/bin
    mkdir -p ~/android/lineage
    curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    chmod a+x ~/bin/repo
    git lfs install
    # in ~/.bash_aliases
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
    fi
    export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G"
    cd ~/android/lineage
    repo init -u https://github.com/LineageOS/android.git -b cm-14.1 --git-lfs
  • 開始同步,第一次同步要非常久!

    repo sync
  • 同步完之後,要準備一些編譯前的檔案

    • device specific files

      cd ~/android/lineage
      source build/envsetup.sh
      breakfast hammerhead
    • 若是第一次使用,要參照此篇從原廠鏡像檔案解出來

      mkdir ~/android/system_dump/
      cd ~/android/system_dump/
      
      # 這邊以 Nexus 5 最後一版 OTA .zip file 為例子
      unzip /mnt/c/Users/tc/Downloads/hammerhead-ota-m4b30z-752c16b1.zip system.transfer.list system.new.dat*
      
      # 原本要從 .new.dat.br 再 format 成 .new.dat,但因為 Nexus 5 的 OTA 已經是就略過
      
      # build .img and mount
      git clone https://github.com/xpirt/sdat2img
      python sdat2img/sdat2img.py system.transfer.list system.new.dat system.img
      mkdir system_tmp/
      sudo mount system.img system_tmp/
      
      # 解 vendors
      rsync -av system_tmp/ system/
      cd system
      tar xf /mnt/c/Users/tc/Downloads/broadcom-hammerhead-m4b30z-21cf8433.tgz
      tar xf /mnt/c/Users/tc/Downloads/lge-hammerhead-m4b30z-520d054d.tgz
      tar xf /mnt/c/Users/tc/Downloads/qcom-hammerhead-m4b30z-d6c0fe26.tgz
      # 記得 ./extract-*.sh 一個個來,因為要 accept
      ./extract-broadcom-hammerhead.sh
      ./extract-lge-hammerhead.sh
      ./extract-qcom-hammerhead.sh
      
      # 從 mount 的資料夾解
      cd ~/android/lineage/device/lge/hammerhead
      ./extract-files.sh ~/android/system_dump/
      
      # cleanup
      sudo umount ~/android/system_dump/system_tmp
      rm -rf ~/android/system_dump/
  • Or extract the necessary files from existing LineageOS on Nexus 5

    cd ~/android/lineage/device/lge/hammerhead
    ./extract-files.sh
  • 開始編譯

    cd ~/android/lineage/device/lge/hammerhead
    source ~/.lineage_venv/bin/activate
    brunch hammerhead

© 2019 ~ 2024 Hsüan, Powered by Gatsby, Theme Material UI