本文主要记录Android 6.0.1源码编译的过程。
编译环境:Ubuntu 20.04.4、Nexus 5、Android 6.0.1、磁盘空间450G+、内存8G
初始化编译环境
1 sudo apt 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 libgl1-mesa-dev libncurses5 libxml2-utils xsltproc unzip vim
配置交换内存
1 2 3 4 5 6 7 8 9 sudo dd if=/dev/zero of=/swapfile bs=1M count=8k sudo mkswap /swapfile sudo swapon /swapfile sudo swapoff /swapfile sudo apt install vim sudo vim /etc/fstab /swapfile none swap sw 0 3 reboot
配置adb
1 2 3 4 vim ~/.bashrc export ADB_PATH=/home/tom/Desktop/Android/platform-tools export PATH=$PATH:$ADB_PATH source ~/.bashrc
配置repo
1 2 3 4 5 6 7 8 9 sudo apt install curl curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o /home/tom/bin/repo chmod +x ~/bin/repo vim ~/.bashrc export REPO_PATH=/home/tom/bin export PATH=$PATH:$REPO_PATH export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo' source ~/.bashrc
配置anaconda3
1 2 3 4 5 6 7 8 vim ~/.bashrc export ANACONDA_PATH=/home/tom/anaconda3/bin export PATH=$PATH:$ANACONDA_PATH source ~/.bashrc conda create -n python2.7 python=2.7 source activate conda activate python2.7
配置git
1 2 3 sudo apt install git git config --global user.name "tom" git config --global user.email "tom@outlook.com"
初始化厂库
1 2 repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-6.0.1_r77 repo sync
漫长的等待,一下午and一晚上。
Ubuntu锁屏设置
Settings->Power-Never
配置openjdk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 tar -xzf openjdk-7u75-b13-linux-x64-18_dec_2014.tar.gz mv java-se-7u75-ri/ /home/tom/bin/ sudo vim /etc/profile export JAVA_HOME=/home/tom/bin/java-se-7u75-ri export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin source /etc/profile sudo update-alternatives --install /usr/bin/java java /home/tom/bin/java-se-7u75-ri/bin/java 3 sudo update-alternatives --install /usr/bin/javac javac /home/tom/bin/java-se-7u75-ri/bin/javac 3 sudo update-alternatives --install /usr/bin/javadoc javadoc /home/tom/bin/java-se-7u75-ri/bin/javadoc 3 vim build/envsetup.sh # 直接搜索set_java_home 修改JAVA_HOME为/home/tom/bin/java-se-7u75-ri vim build/core/main.mk :set number 注释掉171行的终止命令 #$(error stop)
下载、解压和安装驱动文件
地址:https://developers.google.com/android/drivers#hammerheadktu84p
1 2 3 4 5 6 7 8 tar -xzf broadcom-hammerhead-m4b30z-21cf8433.tgz tar -xzf lge-hammerhead-m4b30z-520d054d.tgz tar -xzf qcom-hammerhead-m4b30z-d6c0fe26.tgz mv ./*sh /home/tom/Desktop/SourceCode/Android6/ sh extract-broadcom-hammerhead.sh sh extract-lge-hammerhead.sh sh extract-qcom-hammerhead.sh
编译异常处理
修改源码art/build/Android.common_build.mk
里的内容 ifneq ($(WITHOUT_HOST_CLANG),true) ==> ifeq ($(WITHOUT_HOST_CLANG),false)
设置高速缓存
1 2 3 4 echo export USE_CCACHE=1 >> ~/.bashrc source ~/.bashrc prebuilts/misc/linux-x86/ccache/ccache -M 50G
报错curl: option --no-proxy: used '--no-' for option that isn't a boolean
将/prebuilts/sdk/tools
下面的jack第128行以及jack-admin
第123行中的--no-proxy
改为--noproxy
其它尝试解决报错3用到的命令,可能没什么用..
1 2 3 export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx6g" export LC_ALL=C export JACK_JAR=./out/host/linux-x86/framework/jack.jar
编译
1 2 3 4 make clobber source build/envsetup.sh lunch make -j10
历时1h10min,终于成功了
刷机命令
1 2 3 4 fastboot flash boot boot.img fastboot flash system system.img fastboot flash cache cache.img fastboot flash userdata userdata.img
参考文章
[原创]源码编译(1)——Android6.0源码编译详解
curl: option --no-proxy: used '--no-' for option that isn't a boolean
Difference between --noproxy and --no-proxy?