源碼下載
下載時(shí)間:2018-04-28
系統(tǒng)版本:android-6.0.1_r63
大谢礁浴:107G左右
環(huán)境要求
OS ubuntu16.04
安裝repo
安裝curl
安裝git
上面的工具環(huán)境如果沒(méi)有介劫,可以自己使用apt-get命令去安裝洁桌,方法也很簡(jiǎn)單,不在此處贅述。
準(zhǔn)備工作
1.安裝jdk,這個(gè)是jdk1.8,我下載版本編譯需要jdk1.7
sudo apt-get update
sudo apt-get install openjdk-8-jdk
2.安裝必要讀組建包
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
1.下載 repo 工具
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
2.建立工作目錄
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
3.初始化倉(cāng)庫(kù)
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
注:如果提示無(wú)法連接到 gerrit.googlesource.com佩谣,請(qǐng)參照以下方法
下載
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
為了方便可以將其拷貝到你的PATH里凡怎。
更新
repo的運(yùn)行過(guò)程中會(huì)嘗試訪問(wèn)官方的git源更新自己,如果想使用tuna的鏡像源進(jìn)行更新宫蛆,可以將如下內(nèi)容復(fù)制到你的~/.bashrc里
cd ~/.bashrc
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
并重啟終端模擬器艘包。
4.如果需要某個(gè)特定的 Android 版本(列表):
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-6.0.1_r63
5.同步源碼樹(shù)(以后只需執(zhí)行這條命令來(lái)同步)
repo sync
下載常見(jiàn)問(wèn)題
1.下載命令結(jié)束,提示error耀盗,只需要重復(fù)執(zhí)行repo sync 即可想虎。
編譯源碼
1.清理
make clobber
2.設(shè)置環(huán)境
source build/envsetup.sh
或者
. build/envsetup.sh
3.選擇一個(gè)目標(biāo)
lunch aosp_arm-eng
4.構(gòu)建代碼
make -j4
5.##模擬 Android 設(shè)備
編譯流程會(huì)自動(dòng)將模擬器添加到您的路徑中。要運(yùn)行模擬器叛拷,請(qǐng)輸入以下命令:
emulator
6.重新生成img
make snod
編譯常見(jiàn)問(wèn)題
1.You are attempting to build with the incorrect version
of java.
Your version is: openjdk version "1.8.0_162" OpenJDK Runtime Environment (build 1.8.0_162-8u162-b12-0ubuntu0.16.04.2-b12) OpenJDK 64-Bit Server VM (build 25.162-b12, mixed mode).
The required version is: "1.7.x"
Please follow the machine setup instructions at
https://source.android.com/source/initializing.html
解決方法1
執(zhí)行
export EXPERIMENTAL_USE_JAVA8=true
解決方法2
由于編譯android源碼需要openjdk1.7.X版本舌厨。ubuntu 16.04自帶openjdk為1.8.X版本。
sudo apt-get install openjdk-7-jre 或者sudo apt-get install openjdk-7-jdk
如果出現(xiàn)
--------沒(méi)有可用的軟件包 openjdk-7-jdk忿薇,但是它被其它的軟件包引用了裙椭。
這可能意味著這個(gè)缺失的軟件包可能已被廢棄, 或者只能在其他發(fā)布源中找到
E: 軟件包 openjdk-7-jdk 沒(méi)有可安裝候選
可以按照一下操作安裝1.7.X版本
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk
如果安裝成功之后還是不能用可能不有多個(gè)版本煌恢,選的不對(duì)
sudo update-alternatives --config java
sudo update-alternatives --config javac
選出正確的版本
2.recipe for target 'out/host/linux-x86/obj/lib/libart.so' failed
trip: libpagemap_32 (out/target/product/xx/obj_arm/lib/libpagemap.so)
target Strip: librilutils_32 (out/target/product/xx/obj_arm/lib/librilutils.so)
target Strip: libtinyxml_32 (out/target/product/xx/obj_arm/lib/libtinyxml.so)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
drivers/soc/qcom/Kconfig:310:warning: choice value used outside its choice group
drivers/soc/qcom/Kconfig:315:warning: choice value used outside its choice group
configuration written to .config
make[2]: Leaving directory '/home/xx/xx/6.0/android/xx/out/target/product/xx/obj/KERNEL_OBJ'
make[1]: Leaving directory '/home/xx/xx/6.0/android/xx/kernel'
make[1]: Entering directory '/home/xx/xx/6.0/android/xx/kernel'
make[2]: Entering directory '/home/xx/xx/6.0/android/xx/out/target/product/xx/obj/KERNEL_OBJ'
build/core/host_shared_library_internal.mk:51: recipe for target 'out/host/linux-x86/obj/lib/libart.so' failed
make: *** [out/host/linux-x86/obj/lib/libart.so] Error 1
make: *** 正在等待未完成的任務(wù)....
clang編譯器導(dǎo)致的問(wèn)題骇陈,目前可行的修改方法時(shí)在art/build/Android.common_build.mk ,中將host 默認(rèn)編輯器使用clang關(guān)掉,找到WITHOUT_HOST_CLANG
關(guān)閉clang即可
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := false
endif