1. 环境准备和介绍
软件环境:VMware Workstation Pro + Ubuntu 16.04 64 bit,虚拟机的内存配置6GB,4个CPU
硬件环境:RaspBerry Pi3 + 16GB SD卡
测试Android版本:Android-7.1.2_r19
2.下载Android源码
Repo是一个用于方便管理Android代码的一个工具,管理Android使用的多个Git库。
mkdir ~/bin
export PATH=$PATH:$HOME/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
sudo apt-get install python-mako
$ sudo mkdir -p /workspace/raspberry
$cd /workspace/raspberry
$repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r19
$ git clone https://github.com/android-rpi/local_manifests .repo/local_manifests
$ repo sync
sync过程会持续非常长的时间,如果网络状况比较好,大概需要4-5小时。
可以休息一下了,看下下面的下载参考吧。
http://source.android.com/source/downloading.html
https://github.com/android-rpi/local_manifests
3. 编译RPI 3的Android版本
3.1 编译Android的RPI版本
编译过程看起来非常简单,但是编译的时间会很漫长,而且有可能出错。
$ cd kernel/rpi
$ ARCH=arm scripts/kconfig/merge_config.sh arch/arm/configs/bcm2709_defconfig kernel/configs/android-base.config kernel/configs/android-recommended.config
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make zImage
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make dtbs
$ source build/envsetup.sh
$ lunch rpi3-eng
$ make ramdisk systemimage
或者
$make-j4/8/16
如果你有足够的内存和CPU,用-j参数可以加速编译过程,如果内存和CPU太少,就不要加参数慢慢等吧。顺便看看下面的链接
https://github.com/android-rpi/device_brcm_rpi3
3.2 编译中出现的问题
在编译过程中,遇到了两种错误信息,都与内存配置有关,也就是说要编译Android 7来耍一下,你需要至少有5GB以上的内存。
在编译过程中,如果遇到jack-admin报告错误,大体如下,说明你的jack-admin配置的内存不够,请参照下面的解决方法修改prebuilts/sdk/tools/jack-admin中对java参数的配置。
3 warnings
[ 34% 16872/49032] host Java: bouncyca...tle-bcpkix-
host_intermediates/classes)
warning: [options] bootstrap class path not set in conjunction with -
source 1.7
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
[ 34% 16888/49032] Building with Jack:...l_intermediates/with-
local/classes.dex
FAILED: /bin/bash out/target/common/obj/JAVA_LIBRARIES/core-
all_intermediates/with-local/classes.dex.rsp
Communication error with Jack server (56). Try 'jack-diagnose'
ninja: build stopped: subcommand failed.
build/core/ninja.mk:148: recipe for target 'ninja_wrapper' failed
make: *** [ninja_wrapper] Error 1
该问题可以通过如下的修改解决
@ubuntu:/workspace/raspberry/prebuilts/sdk/tools$ diff -Nru jack-admin jack-admin.original
--- jack-admin 2017-08-03 11:46:29.352035527 +0800
+++ jack-admin.original 2017-08-08 10:44:56.580124906 +0800
@@ -451,7 +451,7 @@
if [ "$RUNNING" = 0 ]; then
echo "Server is already running"
else
- JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS-Xmx5120M -cp $LAUNCHER_JAR $LAUNCHER_NAME"
+ JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS cp $LAUNCHER_JAR $LAUNCHER_NAME"
echo "Launching Jack server" $JACK_SERVER_COMMAND
(
trap "" SIGHUP
在我的环境下,用5GB勉强可以工作,低于4.5GB之后该jack-admin问题就会一直报告。如果内存足够,推荐6GB。
4. 准备RPI 3的SD卡
4.1 Partitions of SD card
p1 512MB for BOOT : Do fdisk : W95 FAT32(LBA) & Bootable, mkfs.vfat
p2 512MB for /system : Do fdisk, new primary partition
p3 512MB for /cache : Do fdisk, mkfs.ext4
p4 remainings for /data : Do fdisk, mkfs.ext4
Set volume label for each partition - system, cache, userdata
: use -L option of mkfs.ext4, e2label command, or -n option of mkfs.vfat
4.2 Install kernel and ramdisk to BOOT partition
cp -rf device/brcm/rpi3/boot/* /media/xxx/boot/
cp -rf kernel/rpi/arch/arm/boot/zImage /media/xxx/boot/
cp -rf kernel/rpi/arch/arm/boot/dts/bcm2710-rpi-3-b.dtb /media/xxx/boot/dts
cp -rf kernel/rpi/arch/arm/boot/dts/overlays/vc4-kms-v3d.dtbo /media/xxx/boot/dts/overlays/vc4-kms-v3d.dtbo
cp -rf out/target/product/rpi3/ramdisk.img /media/xxx/boot/
4.3 Install filesystem to SYSTEM partition
$ sudo dd if=out/target/product/rpi3/system.img of=/dev/