Mac編譯Android 8.1


一、配置環境
• 安裝XCode
https://developer.apple.com/xcode/
xcode-select --install
• 安裝JDK
https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html
• 安裝Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
• 安裝工具
brew install git python make curl
• 安裝MacPort
https://www.macports.org/install.php
• 安裝工具
POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg
二、創建磁盤鏡像

hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 200g ~/Documents/android/android.dmg
hdiutil resize -size 250g ~/Documents/android/android.dmg.sparseimage #重新設置映像的大小
hdiutil attach ~/Documents/android/android.dmg.sparseimage -mountpoint /Volumes/android #掛載
hdiutil detach /Volumes/android #彈出映像

三、配置環境變量.bash_profile

# set the number of open files to be 1024
ulimit -S -n 1024
# Compiler cache
export USE_CCACHE=1
# mount the android file image
function mountAndroid { hdiutil attach ~/Documents/android/android.dmg.sparseimage -mountpoint /Volumes/android; }
# unmount the android file image
function umountAndroid() { hdiutil detach /Volumes/android; }
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export PATH=~/Documents/android/bin:$PATH
export ANDROID_JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export PATH=$ANDROID_JAVA_HOME/bin:$PATH
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

四、下載AOSP源代碼
• 下載repo並設置權限

mkdir ~/Documents/android/bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/Documents/android/bin/repo
chmod a+x ~/Documents/android/bin/repo

• 初始化倉庫

mountAndroid
cd /Volumes/android
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.1.0_r62
repo init -u git://aosp.tuna.tsinghua.edu.cn/aosp/platform/manifest
repo init -u git://aosp.tuna.tsinghua.edu.cn/aosp/platform/manifest -b android-8.1.0_r62
repo sync -c

五、編譯AOSP源代碼

cd /Volumes/android/WORKING_DIRECTORY/ 
# Set ccache
prebuilts/misc/darwin-x86/ccache/ccache -M 50G 
# Clean out directory
make clobber 
# Jack server configuration
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx6g"
./prebuilts/sdk/tools/jack-admin kill-server
./prebuilts/sdk/tools/jack-admin start-server 
# Setup environment 
source build/envsetup.sh

# support Mac OS Catalina 10.15
# change ./build/soong/cc/config/x86_darwin_host.go
  darwinSupportedSdkVersions = []string{
          "10.10",
          "10.11",
          "10.12",
          "10.13",
          "10.14",
          "10.15",  // 增加該行
      }
# Segmentation fault
# change ./system/sepolicy/tests/Android.bp
  stl: "libc++_static", // 去除該行

# Select device target
lunch
# Build sources (cofee time)
make -j8

六、安裝

cd out/target/product/<product_name> 
adb reboot bootloader
fastboot oem unlock 
fastboot flashall -w

#燒入
adb reboot bootloader
fastboot flash boot boot.img
fastboot flash system system.img
fastboot flash userdata userdata.img
fastboot flash ramdisk ramdisk.img
fastboot flash vendor vendor.img
fastboot erase cache
fastboot reboot

七、重新編譯單個包

cd WORKING_DIRECTORY
source build/envsetup.sh 
# Select device target
lunch
# Rebuil single pacage (exemple Dialer)
mmm packages/apps/dialer/

# Recompiled package output
cd /out/target/product/<device_targeted>/obj/APPS/<app_name>_intermediates

adb install -r out/target/product/<device_targeted>/system/priv-app/<app_name>/<app_name>.apk
adb reboot

八、編譯系統UI

cd WORKING_DIRECTORY
source build/envsetup.sh
# Select device target
lunch
# Rebuil single pacage (exemple Dialer)
mmm frameworks/base/packages/SystemUI/

adb install -r out/target/product/<device_targeted>/system/priv-app/SystemUI/SystemUI.apk
adb reboot

九、編譯Framework
• Build Framework JAR only: mmm framework/base/
• Build Framework Resources only: mmm framework/base/core/res/

# Root the device
adb root
adb disable-verity
adb reboot
adb remount
# Remove older framework
adb shell
cd /system/framework/
rm framework-res.apk
exit
# Push the new Framework
adb push out/target/product/<device_targeted>/system/framework/framework-res.apk /system/framework/
# Reboot the device
adb reboot

十、簽名
標准 Android 版本使用四個密鑰,所有這些密鑰都位於 :build/target/product/security
• testkey:不指定密鑰的包的通用默認鍵。
• platform:作為核心平台一部分的包的測試密鑰。
• shared:家庭/聯系人進程中共享的內容的測試密鑰。
• media:作為媒體/下載系統一部分的包的測試密鑰。
資料來源:https://source.android.com/devices/tech/ota/sign_builds#certificates-keys
若要使用現有密鑰之一對應用進行簽名,請使用以下指令 (LOCAL_CERTIFICATE)到關聯的makefile Android.mk:
LOCAL_CERTIFICATE := platform


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM