EdwardWu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    9
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Android 第三方 ROM 繁體中文編譯教學 <small>2021.09.01 更新文章 (支援 Android 11) 2022.02.05 更新文章 (支援 Android 12)</small> #### 從零開始的編譯指南 挑選一個想要編譯的第三方 ROM --- - [Havoc OS](https://github.com/Havoc-OS/android_manifest) - [Arrow-OS](https://github.com/ArrowOS/android_manifest) - [crDroid](https://github.com/crdroidandroid/android) - [Pixel Experience](https://github.com/PixelExperience/manifest) - [Lineage OS](https://github.com/LineageOS/android) - 還有其他,這邊僅舉例常見的幾個 ROM 先備知識 --- - Linux 終端指令語法 - git 指令(至少需要基礎的能力) - 永不放棄的心 - 一顆清晰的頭腦 配置一台主機 --- - CPU:建議8核心 - RAM:至少16GB (Android 10),建議配置32GB (Android 12)以上 - 儲存空間容量:至少500GB,建議2TB - 儲存裝置類型:HDD即可 (SATA 3),SSD更好 - 系統:初學者建議安裝 Ubuntu 20.04 LTS 安裝必要的編譯套件 ---- - 臺灣國家高速網路中心 : ``` sudo sed -i 's/tw.archive.ubuntu.com/free.nchc.org.tw/ubuntu' /etc/apt/sources.list sudo sed -i 's/archive.ubuntu.com/free.nchc.org.tw/ubuntu' /etc/apt/sources.list sudo sed -i 's/security.ubuntu.com/free.nchc.org.tw/ubuntu' /etc/apt/sources.list sudo apt-get clean all sudo apt-get update ``` - Ubuntu 18.04 LTS ``` sudo apt 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 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev openjdk-11-jdk git vim repo libwxgtk3.0-dev ``` - Ubuntu 20.04 LTS ``` sudo apt 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 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev openjdk-11-jdk git vim jq ``` 設定 git 環境 ``` git config --global user.email "您的e-mail" git config --global user.name "您的名字" ``` 同步 Android 原始碼 --- #### 參考各個 Android ROM 的 Android Manifest ##### 本文皆以 Arrow-OS(Android 12)與 ASUS ZenFone 5Z (Z01R) 進行舉例 - 先建立資料夾 ``` mkdir -p ~/bin mkdir -p ~/arrow-12 ``` ``` curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo && chmod a+x ~/bin/repo ``` ``` cd ~/arrow-12 ``` ``` repo init -u https://github.com/ArrowOS/android_manifest.git -b arrow-12.0 ``` - 接下來便開始同步 Android 源代碼(大約150GB左右,視 Android 版本不同及編譯的ROM不同而有所差異) ``` repo sync -c -j$(nproc --all) --force-sync --no-clone-bundle --no-tags ``` #### 更新原始碼 - 在這之後如果有需要更新原始碼,請使用 repo sync 進行同步(更新系統原始碼) ``` repo sync ``` - 待所有原始碼同步完成後,還需要配置 Device Tree / Vendor Tree / Kernel Tree - 另外,還需要額外下載 Kernel 的編譯器 #### GCC ``` git clone --depth=1 https://github.com/arter97/arm64-gcc -b master prebuilts/gcc/linux-x86/aarch64/aarch64-elf git clone --depth=1 https://github.com/arter97/arm32-gcc -b master prebuilts/gcc/linux-x86/arm/arm-eabi ``` 或是 ``` git clone --depth=1 https://github.com/mvaisakh/gcc-arm64 -b gcc-master prebuilts/gcc/linux-x86/aarch64/aarch64-elf git clone --depth=1 https://github.com/mvaisakh/gcc-arm -b gcc-master prebuilts/gcc/linux-x86/arm/arm-eabi ``` ``` git clone --depth=1 https://github.com/Edward-Projects/gcc-arm64 -b Z01R prebuilts/gcc/linux-x86/aarch64/aarch64-elf git clone --depth=1 https://github.com/Edward-Projects/gcc-arm -b Z01R prebuilts/gcc/linux-x86/arm/arm-eabi ``` #### Clang ``` git clone --depth=1 https://github.com/kdrag0n/proton-clang -b master prebuilts/clang/host/linux-x86/clang-proton ``` # 修改 Device Tree / Device Common Tree #### 對於初學者來說,修改已經開發完成的Device Tree / Device Common Tree,應該會簡易許多 1. 首先在GitHub上面尋找對應裝置的Device Tree / Device Common Tree 2. Fork一份到自己的 GitHub 帳號底下 3. 修改以下列舉的檔案 ``` # 箭頭表示需要重新命名 AndroidProducts.mk Device.mk extract-files.sh lineage.dependencies → arrow.dependencies lineage_Z01R.mk → arrow_Z01R.mk setup-makefiles.sh overly-lineage/ → overly-arrow/ ``` 4. 在這些檔案及資料夾當中尋找原本的系統所使用的代號,修改成你當前要編譯的系統代號 ###### 參考範例: [Z01R: Initial Arrow bringup](https://github.com/Edward-Projects/android_device_asus_Z01R/commit/e1ea428085d65deda95bc4d5949f99c6a91037fc) 5. 系統代號如下: ``` Havoc OS : havoc Arrow-OS : arrow crDroid : lineage Pixel Experience : aosp Lineage OS : lineage ``` 6. 系統代號有些地方是採用大寫字母,切勿更改為小寫字母,應保留原有樣式 同步 Device Tree / Vendor Tree / Kernel Tree --- ##### 備註一下:有些裝置還有Device Common Tree / Vendor Common Tree / Kernel Common Tree 也要記得同步 ###### 小提醒!!如果有遇到Vendor Tree內包含很多裝置的資料,可以善用文末的資料(最後一個網站) svn co 去下載單一個資料夾的東西 ``` Example: git clone {ssh url} -b {branch name} {directory} git clone Github連結 -b 分支 device/品牌名/機型代號 git clone GitHub連結 -b 分支 device/品牌名/SOC名稱-common git clone Github連結 -b 分支 kernel/品牌名/SOC git clone Github連結 -b 分支 vendor/品牌名 ``` #### 範例如下: ``` git clone git@github.com:Edward-Projects/android_device_asus_Z01R.git -b arrow-12.0 device/asus/Z01R git clone git@github.com:bluehomewu/kernel_z01r.git -b twelve kernel/asus/sdm845 git clone git@github.com:Edward-Projects/proprietary_vendor_asus_Z01R.git -b arrow-12.0 vendor/asus/Z01R ``` - 設定Cache ``` export USE_CCACHE=1 export CCACHE_EXEC=/usr/bin/ccache ccache -M 50G ``` - 都把檔案放置完成後,可以開始進行編譯 ``` . build/envsetup.sh lunch 系統代號_裝置代號-編譯類型 brunch 系統代號_裝置代號-編譯類型 ``` #### 範例如下: ``` . build/envsetup.sh lunch arrow_Z01R-userdebug brunch arrow_Z01R-userdebug ``` # 腳本 ### 編譯ROM腳本 ``` #!/bin/bash #Build 裝置代號 cd ~/arrow . build/envsetup.sh brunch 系統代號_裝置代號-編譯類型| tee 系統代號_裝置代號_$(date +"%Y%m%d_%H.%M")GMT8.txt ``` #### 範例如下: ``` #!/bin/bash #Build Z01R cd ~/arrow . build/envsetup.sh brunch arrow_Z01R-userdebug | tee arrow_Z01R_$(date +"%Y%m%d_%H.%M")GMT8.txt ``` ### 同步 Device Tree / Vendor Tree / Kernel Tree 的腳本 #### 把這個腳本修改完成後,保存成roomservices.xml檔案,複製至 ``` ~/havoc/.repo/local_manifest ``` ``` <?xml version="1.0" encoding="UTF-8"?> <manifest> <project path="vendor/品牌名" name="帳號/repo name" remote="github" revision="分支名" /> <project path="device/品牌名/機型代號" name="帳號/repo name" remote="github" revision="分支名" /> <project path="kernel/品牌名/SOC" name="帳號/repo name" remote="github" revision="分支名" /> <project path="prebuilts/gcc/linux-x86/aarch64/aarch64-elf" name="Edward-Projects/gcc-arm64" remote="github" revision="Z01R" clone-depth="1" /> <project path="prebuilts/gcc/linux-x86/arm/arm-eabi" name="Edward-Projects/gcc-arm" remote="github" revision="Z01R" clone-depth="1" /> </manifest> ``` #### 範例如下: ``` <?xml version="1.0" encoding="UTF-8"?> <manifest> <project path="vendor/asus/Z01R" name="Edward-Projects/proprietary_vendor_asus_Z01R" remote="github" revision="arrow-12.0" /> <project path="device/asus/Z01R" name="Edward-Projects/android_device_asus_Z01R" remote="github" revision="arrow-12.0" /> <project path="kernel/asus/sdm845" name="bluehomewu/kernel_z01r" remote="github" revision="twelve" /> <project path="prebuilts/gcc/linux-x86/aarch64/aarch64-elf" name="Edward-Projects/gcc-arm64" remote="github" revision="Z01R" clone-depth="1" /> <project path="prebuilts/gcc/linux-x86/arm/arm-eabi" name="Edward-Projects/gcc-arm" remote="github" revision="Z01R" clone-depth="1" /> </manifest> ``` # Happy Hacking!! # 其他注意事項 ### 編譯 ROM 是一個大工程 - 推薦在編譯的時候使用 tmux 指令去新增一個 session 以便把當前的工作階段保留在背景 - 編譯的同時建議在( brunch 系統代號_機型代號-編譯類型)後方加上 tee 指令,方便保存log檔案,如果有遇到 FAILED 便可以找到問題來源 - 如果要上傳檔案到雲端硬碟,推薦使用 rclone 上傳檔案 - 需要熟悉 git 指令 - 建議編寫一些簡單的腳本方便自己執行命令 #### 參考資料連結: 1. [tmux](https://git.io/JIUrH) 2. [tee](http://linux.vbird.org/linux_basic/0320bash.php#pipe_3) 3. [rclone](https://www.timelate.com/archives/install-rclone-on-ubuntu.html) 4. [為你自己學 Git 筆記 — GitHub 應用篇](https://link.medium.com/oQfJxibSRbb) [修改 Commit 紀錄](https://gitbook.tw/chapters/using-git/amend-commit1.html) [剛才的 Commit 後悔了,想要拆掉重做…](https://gitbook.tw/chapters/using-git/reset-commit.html) [追加檔案到最近一次的 Commit](https://gitbook.tw/chapters/using-git/amend-commit2.html) [同步遠端分支](https://zlargon.gitbooks.io/git-tutorial/content/remote/sync.html) [Git 基礎 - 與遠端協同工作](https://git-scm.com/book/zh-tw/v2/Git-%E5%9F%BA%E7%A4%8E-%E8%88%87%E9%81%A0%E7%AB%AF%E5%8D%94%E5%90%8C%E5%B7%A5%E4%BD%9C) [rename git branch locally and remotely](https://git.io/JIUKI) [Git cherry-pick from another repository](https://coderwall.com/p/sgpksw/git-cherry-pick-from-another-repository) [使用 Git 時如何做出跨 repo 的 cherry-pick](https://blog.m157q.tw/posts/2017/12/30/git-cross-repo-cherry-pick/) [git 場景 :從一個分支cherry-pick多個commit](https://www.itread01.com/content/1529341336.html) [合併發生衝突了,怎麼辦?](https://gitbook.tw/chapters/branch/fix-conflict.html) [下載Github上特定Repository內的資料夾](https://notes.andywu.tw/2018/%e4%b8%8b%e8%bc%89github%e4%b8%8a%e7%89%b9%e5%ae%9arepository%e5%85%a7%e7%9a%84%e8%b3%87%e6%96%99%e5%a4%be/) # Q&A 1. 編譯過程遇到 FAILED 的時候,可以嘗試去看看哪個檔案造成的,它會寫在 FAILED 的後方 2. 如果真的遇到自己無法解決的問題,可以加入這三個 Telegram 群組 [Android Building Help](https://t.me/AndroidBuildersHelp) [RomDevelopment](https://t.me/alaskalinuxuser_romdevelopment) [Android OS Building Support](https://t.me/android_builders_help) 3. [快速上手 Android Custom ROM 適配 - Prebuilt Vendor](https://hackmd.io/@EdwardWu/Prebuilt-bringup) 4. 等我想到還有什麼問題再加上來 ## 聯絡我 - Telegram:[Edward Wu](https://t.me/edwardwu0223) - 行有餘力的話,可以考慮捐款給我 [Paypal](https://www.paypal.me/edwardwu0223) - 同場加映 [Android 第三方 Recovery 繁體中文編譯教學](https://hackmd.io/@EdwardWu/CompileARecovery) <p align="center"> <a href="https://github.com/bluehomewu"> <img src="https://img.shields.io/badge/-Github-000?style=flat&logo=Github&logoColor=white" /></a> <a href="mailto:bluehome.wu@gmail.com"> <img src="https://img.shields.io/badge/-Gmail-c14438?style=flat&logo=Gmail&logoColor=white" /></p></a> ###### tags: `Android` `ROM` `編譯` `第三方` `教學`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully