android aosp 開發環境搭建


  https://source.android.com/source/initializing

ubuntu開發環境

建議按照官方推薦的來,之前折騰centos,各種依賴,版本原因耗費大量時間。實體機安裝ubuntu14.04server版。

1、安裝依賴

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
  lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
  libgl1-mesa-dev libxml2-utils xsltproc unzip

 2、安裝openjdk,openjdk版本與你要編譯的版本相關,在官網上有介紹。我要編譯android 6,使用openjdk7

$ sudo apt-get install openjdk-7-jdk

 

下載aosp
這里要用到清華的鏡像https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
1、准備repo工具

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

 編輯~/bin/repo文件,將REPO_URL修改為https://mirrors.tuna.tsinghua.edu.cn/git/git-repo

2、配置git

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global http.postBuffer 24288000

 3、下載源碼

  • https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/ 下載源碼包aosp-latest.tar,建議windows迅雷下載
  • 解壓源碼包並同步到你想編譯的源碼版本,這里編譯的是:
    MDA89D     android-6.0.0_r11     Marshmallow     Nexus 6P
    
    $ tar xf aosp-latest.tar
    $ cd aosp
    $ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-6.0.0_r11
    $ repo sync
    
  • 開始編譯 
    $ . build/envsetup.sh
    $ lunch aosp_angler-userdebug
    $ make -jN 

  

內核編譯

1.下載內核源碼

$ git clone https://aosp.tuna.tsinghua.edu.cn/kernel/msm       
$ cd msm
$ git branch -a
$ git checkout origin/android-msm-angler-3.10-marshmallow-mr1

 2.下載arm64工具鏈aarch64-linux-android-4.9

$ git clone https://aosp.tuna.tsinghua.edu.cn/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9

 3.配置環境變量

$ export PATH=$PWD/aarch64-linux-android-4.9/bin:$PATH
$ export ARCH=arm64
$ export SUBARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-android-

 4.編譯

$ make angler_defconfig
# make

 

打包boot.img

上一步編譯生成的內核鏡像,需要打包成boot.img。boot.img通常由以下三部分構成:

  • A kernel image
  • A ramdisk image
  • A kernel command-line

 


這里我們使用官方的boot.image,將之前編譯生成的kernel替換原有的。官方Factory image https://developers.google.com/android/images

對應之前的MDA89D,選擇下載:

angler-mda89d-factory-9f001626.zip

 從官方的boot.img中提取出bootimg.cfg  zImage initrd.img

$ unzip angler-mda89d-factory-9f001626.zip 
$ cd angler-mda89d
$ unzip image-angler-mda89d.zip boot.img
$ abootimg -x boot.img 
  • bootimg.cfg: configuration with addresses, sizes and the kernel commandline.
  • zImage: the stock kernel
  • initrd.img: the stock ramdisk

我們編譯的內核大小和提取出來的不一樣,需要修改bootimg.cfg,刪掉bootsize那項

sed -i '/bootsize =/d' bootimg.cfg

 接下來便可以生成自定義的boot鏡像,這里命名為newboot.img

abootimg --create newboot.img -f bootimg.cfg -k your_kernel_path/msm/arch/arm64/boot/Image.gz-dtb -r initrd.img

 


免責聲明!

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



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