下载:
ubuntu-releases-16.04安装包下载_开源镜像站-阿里云 (aliyun.com) http://mirrors.aliyun.com/ubuntu-releases/16.04/
编译环境:
- linux : ubuntu 16.04 内存2G 处理器 2核 缓存5G 硬盘100G
- 虚拟机: VBox
- Android版本:Android4.4
说明:
1. 需要内存要大于1G,我用1G内存编译提示内存分配失败。
2. 在虚拟机上编译,需要增加缓存的大小,我配置的是5G
3. 本文编译的不是Android原生的源码,是全志提供的SDK 针对T-Foucs T3 设备
(一)代码下载
(1)repo下载和安装
Android使用repo管理代码,所以需要在linux上安装repo
1. 根目录下创建.bin文件夹
mkdir ~/.bin
sudo apt-get install curl -y
sudo apt-get install git -y
sudo apt-get install vim -y
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
chmod a+x ~/.bin/repo
2. 配置为环境变量
echo 'export PATH=$PATH:$HOME/.bin' > ~/.bashrc
使配置生效
source ~/.bashrc
3. 创建同步源码的工作目录
mkdir ~/.android_source
4. 在工作目录中创建.repo目录
cd ~/.android_source
mkdir .repo
5. 可以初始化git代码了
(2)下载代码
代码下载这里只是个示例,需要自己去找自己需要下载版本的链接。
cd android
初始化代码仓:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
同步代码:
repo sync
(二)安装依赖库
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
(三)安装JDK6.0
Android4.4 依赖的是JDK6.0,不能直接使用命令apt-get install,据说是版权问题,可以自己安装。我使用的是Linux x64 JDK6
可以在下面链接下载Linux x64 JDK6:
链接:https://pan.baidu.com/s/1LaW5twh_90vztSFPKxkspg
提取码:gggb
下载解压后将bin文件拷贝到linux系统下,切换到root权限
# mkdir /usr/java 创建安装路径
# ./jdk-6u45-linux-x64.bin 完成安装
设置环境变量
# vim /etc/profile
在打开的文件末尾添加一下内容:
export JAVA_HOME=/usr/java/jdk1.6.0_45
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
然后保存,关闭文件
设置默认的SDK
sudo update-alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_45/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_45/bin/javac 300
更新环境变量
# . /etc/profile
查看当前Java版本
# java -version
显示如下内容说明安装成功,可以开始工作喽:
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
(四)编译Android4.4代码
(1)初始编译环境
source build/envsetup.sh
biao@ubuntu:~/android$ source build/envsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/asus/deb/vendorsetup.sh
including device/generic/mips/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/softwinner/t3-p3/vendorsetup.sh
including device/softwinner/t3-adas/vendorsetup.sh
including device/softwinner/t3-23m/vendorsetup.sh
including device/softwinner/t3-p2/vendorsetup.sh
including device/softwinner/t3-p1/vendorsetup.sh
including device/softwinner/common/vendorsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/lge/mako/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including sdk/bash_completion/adb.bash
biao@ubuntu:~/android$
(2)选择编译目标
执行lunch命令:
biao@ubuntu:~/android$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_x86-eng
3. aosp_mips-eng
4. vbox_x86-eng
5. aosp_tilapia-userdebug
6. aosp_flo-userdebug
7. aosp_grouper-userdebug
8. aosp_deb-userdebug
9. mini_mips-userdebug
10. mini_x86-userdebug
11. mini_armv7a_neon-userdebug
12. t3_p3-eng
13. t3_adas-eng
14. t3_adas-user
15. t3_23m-eng
16. t3_23m-user
17. t3_p2-eng
18. t3_p1-eng
19. t3_p1-user
20. aosp_manta-userdebug
21. aosp_mako-userdebug
22. aosp_hammerhead-userdebug
Which would you like? [aosp_arm-eng] 18
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.4.2
TARGET_PRODUCT=t3_p1
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a7
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.8.0-36-generic-x86_64-with-Ubuntu-16.04-xenial
HOST_BUILD_TYPE=release
BUILD_ID=KOT49H
OUT_DIR=out
============================================
biao@ubuntu:~/android$
(3)拷贝硬件相关文件
执行命令:extract-bsp
该步骤是在全志平台上有的,其它平台不一定相同。主要进行的是将linux中更硬件平台相关的文件拷贝到Android相应的目录中去。
(4)编译源码
make -j2 && pack
-j2 是多线程编译,跟CPU数有关,最大是CPU数的2倍