特别提醒:Android2.3需要gcc-4.4、g+±4.4、JDK6、make3.8.1
1. 安装gcc-4.4和g+±4.4
sudo apt-get autoremove gcc
sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 44
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 44
选择gcc-4.4和g+±4.4
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
查看是否安装成功
g++ -v gcc -v
2. 安装JDK6
下载
https://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html
安装
cd /usr/local
sudo ./jdk-6u45-linux-x64.bin
配置环境变量
sudo cp -r jdk1.6.0_45 /usr/local/java
sudo vi /etc/profile
# 添加以下内容
export JAVA_HOME=/usr/local/java/jdk1.6.0_45
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME:$PATH
source /etc/profile或者注销系统,查看jdk是否安装成功 java -version javac -version
# 使用update-alternatives进行配置
sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.6.0_45/bin/java 16045
sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.6.0_45/bin/javac 16045
sudo update-alternatives --install /usr/bin/jar jar /usr/local/java/jdk1.6.0_45/bin/jar 16045
sudo update-alternatives --install /usr/bin/javah javah /usr/local/java/jdk1.6.0_45/bin/javah 16045
sudo update-alternatives --install /usr/bin/javap javap /usr/local/java/jdk1.6.0_45/bin/javap 16045
sudo update-alternatives --config name 在不同的Java版本之间切换
3. 安装依赖
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. 安装git和curl工具
sudo apt-get install git-core curl
2.repo工具配置
# 下载repo
cd /bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod a+x repo
# 设置repo下载源清华大学镜像站
vi /bin/repo,将REPO_URL 一行替换成下面的:
REPO_URL = 'https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
# 测试repo是否安装成功
在其它非系统环境变量目录执行repo命令,看是否有这样的输出
error: repo is not installed. Use "repo init" to install it here.
3. 初始化仓库
# 建立Android文件夹
mkdir Android
cd Android
# 主线版本
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
# 特定版本
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-2.3.1_r1
4. 同步源码树
# 以后只需执行这条命令来同步
repo sync或repo sync -j4(四线程同步)
5. 查看版本号
# 搜索该文件中的 PLATFORM_VERSION值
build\core\version_defaults.mk
6. 编译
# 编译整个Android内核源代码
cd Android
make -j4
# 编译特定模块
cd Android
source build/envsetup.sh
mmm pathname(路径名)
7. 启动模拟器
export PATH=$PATH:~/Android/out/host/linux-x86/bin
export ANDROID_PRODUCT_OUT=~/Android/out/target/product/generic
# 启动Google自带内核
emulator
# 启动自己编译的内核
emulator -kernel kernel/goldfish/arch/arm/boot/zImage
# 查看内核版本号
adb shell
cat /proc/version
1. 下载
cd Android
mkdir kernel
git clone https://aosp.tuna.tsinghua.edu.cn/android/kernel/goldfish.git
cd goldfish
git branch -a
git checkout remotes/origin/android-goldfish-2.6.29
2. 编译
cd Android/kernel/goldfish
# 修改Makefile文件
ARCH ?= arm
CROSS_COMPILE ?= arm-eabi-
# 配置环境变量
export PATH=$PATH:~/Android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
# 编译
make goldfish_defconfig
make -j4
错误1
error: dalvik/vm/native/dalvik_system_Zygote.c:191:19: error: storage size of ‘rlim’ isn’t known
struct rlimit rlim;
解决办法:
添加头文件#include 到以下文件
dalvik/vm/native/dalvik_system_Zygote.cpp
错误2
In file included from system/extras/ext4_utils/output_file.c:30: /usr/include/zlib.h:34: fatal error: zconf.h: 没有那个文件或目录 compilation terminated.
解决办法:
原因是zlib1g-dev有个头文件修改了路径,及zconf.h放到了/usr/include/x86_64-linux-gnu/,所以将其拷贝到/usr/include/下即可
错误3
SDL init failure, reason is: No available video device
解决办法:
sudo apt-get install libsdl1.2debian:i386