Android 編譯環境
Android 編譯
Android屬崁入式系統, 需於Ubuntu系統進行cross compile的工作. 編譯時, 需使用大量的cpu及Ram資源. Ram一般要求要到8G以上. 雖說在Windows上使用VMware也可以編譯, 但編譯時間可能會長達3~4小時. 故建議在純Ubuntu系統中, 且CPU使用i7 8核來編譯, 編譯時間可縮短到1.5hrs.
Android原始碼高達10G以上, 再加上編譯時期的暫存檔, repo, git檔, 建議硬碟空間至少要有100G的空間
Ubuntu版本
目前測試最高可用版本為14.04. 結尾的04版為LTS(Long Time Support), 結尾為10版盡量不要使用。15.04, 16.04皆不適用於編譯Android系統
Jdk 版本
編譯Android系統, 僅可使用 jdk 6.0的版本, 7及8皆不適用。但若是開發Android App, 需使用最新的版本才會正常. 故建議編譯系統時, 使用Ubuntu+jdk6.0. 開發App則於Windows+jdk8.0
cd /usr/local
sudo ~/jdk-6u45-linux-x64.bin
然後於/etc/profile加入如下路徑設定
export PATH=/usr/local/jdk1.6.0_45/bin:$PATH
adb 設定
adb 存於sdk/platform-tools中,需於 https://developer.android.com/ 下載, 然後會存於~/Android/Sdk/platform-tools之下. 因為開發App盡可能在Windows之下, 所以可以把adb copy到/usr/bin中, 再刪除SDK目錄
sudo cp ~/Android/Sdk/platform-tools/adb /usr/bin
sudo chmod 7777 /usr/bin/adb
套件安裝
以下為編譯MTK 6582所建議安裝之套件
sudo apt-get install -y git gnupg flex bison gperf zip curl \
libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 \
libreadline-dev:i386 gcc-multilib g++-multilib libxml2-utils \
lib32z1 xsltproc gawk tofrodos libgl1-mesa-dev python-markdown \
libxml2-utils zlib1g-dev:i386 nasm libx264-dev libswscale-dev \
libavformat-dev libffmpeg-nvenc-dev gstreamer1.0-libav \
ffmpeg libffms2-dev
開始編譯
安裝repo
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
安裝Java 7.0 SE
Raspberry 只能使用openjdk-7進行編譯,不可使用Oracle的Jdk
sudo apt-get install openjdk-7-jdk
下載Android Source
mkdir /data/rpi2
cd /data/rpi2
~/bin/repo init -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r13
cd .repo
git clone https://github.com/peyo-hd/local_manifests -b marshmallow
repo sync
備份
若要進行最原始的程式碼備份, 使用如下指令
tar zcvf rpi2.tar.gz rpi2
解壓原始碼
tar xvf rpi2.tar.gz
Build Kernel
安裝 gcc-arm-linux-gnueabihf
sudo apt-get install gcc-arm-linux-gnueabihf
core=$(cat /proc/cpuinfo | grep processor | wc -l)
cd kernel/rpi
ARCH=arm scripts/kconfig/merge_config.sh arch/arm/configs/bcm2709_defconfig android/configs/android-base.cfg android/configs/android-recommended.cfg
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make zImage -j$core
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make dtbs -j$core
*-j$(core) : 全速使用所有的cpu資源
Install python mako module
sudo apt-get install python-mako
Patch frameworks/base
Do https://github.com/peyo-hd/device_brcm_rpi2/wiki#avoid-logcat-flood
Apply following patch under frameworks/base, to avoid logcat flood by mouse event.
framework/base/core/java/android/view/GestureDetector.java
@@ line 490 @@ public class GestureDetector {
public boolean onTouchEvent(MotionEvent ev) {
+ switch(ev.getAction() & MotionEvent.ACTION_MASK) {
+ case MotionEvent.ACTION_HOVER_MOVE:
+ case MotionEvent.ACTION_HOVER_ENTER:
+ case MotionEvent.ACTION_HOVER_EXIT:
+ case MotionEvent.ACTION_BUTTON_PRESS:
+ case MotionEvent.ACTION_BUTTON_RELEASE:
+ case MotionEvent.ACTION_SCROLL:
+ return false;
+ }
if (mInputEventConsistencyVerifier != null) {
Enable GLSurfaceView
Currently mesa3d vc4 build is supporting only following formats.
RGB 565, Alpha 0, Depth 24 or 0, Stencil 8 or 0
RGB 888, Alpha 8, Depth 24 or 0, Stencil 8 or 0
Then apply following patch under frameworks/base, to modify default EGL config.
opengl/java/android/opengl/GLSurfaceView.java
@@ line 976 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
public SimpleEGLConfigChooser(boolean withDepthBuffer) {
- super(8, 8, 8, 0, withDepthBuffer ? 16 : 0, 0);
+ super(8, 8, 8, 8, withDepthBuffer ? 24 : 0, 0);
}
Avoid screen flashing
On eng build, Strict mode behavior – flash screen when apps do long operations on main thread – is enabled by default. We can avoid it by applying following patch under frameworks/base. This option could be turned on via Settings -> Developer options -> Strict mode enabled.
core/java/android/os/StrictMode.java
@@ line 1068 @@ public final class StrictMode {
if (IS_ENG_BUILD) {
- doFlashes = true;
}
Enable SW video decoder
HW video decoder is not ready yet. SW mode could be used by applying following patch under frameworks/av – with limited size & performance.
frameworks/av/media/libstagefright/colorconversion/SoftwareRenderer.cpp
@@ line 113 @@ void SoftwareRenderer::resetFormatIfChanged(const sp<AMessage> &format) {
case OMX_TI_COLOR_FormatYUV420PackedSemiPlanar:
{
- halFormat = HAL_PIXEL_FORMAT_YV12;
- bufWidth = (mCropWidth + 1) & ~1;
- bufHeight = (mCropHeight + 1) & ~1;
break;
}
Build Android source
Continue build with http://source.android.com/source/building.html
source build/envsetup.sh
lunch rpi2-eng
make -j$(core)
Prepare sd card
Partitions of the card should be set-up like followings.
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.ex4
Set volume label for each partition – system, cache, userdata
: use -L option of mkfs.ext4, e2label command, or -n option of mkfs.vfat
Write system partition
cd out/target/product/rpi2
sudo dd if=system.img of=/dev/<p2> bs=1M
Boot partition, kernel & ramdisk
device/brcm/rpi2/boot/* to p1:/
kernel/rpi/arch/arm/boot/zImage to p1:/
kernel/rpi/arch/arm/boot/dts/bcm2709-rpi-2-b.dtb to p1:/
out/target/product/rpi2/ramdisk.img to p1:/
Pi3 Android 7.0 source code
repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r19 cd .repo git clone https://github.com/android-rpi/local_manifests .repo/local_manifests repo sync https://github.com/android-rpi/device_brcm_rpi3.git # Download Android source with patches(local_manifests) Refer to http://source.android.com/source/downloading.html $ repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.1_r6 $ cd .repo $ git clone https://github.com/peyo-hd/local_manifests -b nougat $ repo sync # Build for Raspberry Pi3 See https://github.com/peyo-hd/device_brcm_rpi3
Build PI3
# Build Kernel Install gcc-arm-linux-gnueabihf $ 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 # Install python mako module sudo apt-get install python-mako # Build Android source Continue build with http://source.android.com/source/building.html $ source build/envsetup.sh $ lunch rpi3-eng $ make ramdisk systemimage # Help for build failure : https://github.com/android-rpi/device_brcm_rpi3/wiki/Build-Errors # Prepare sd card Partitions of the card should be set-up like followings. 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 # Write system partition $ cd out/target/product/rpi3 $ sudo dd if=system.img of=/dev/<p2> bs=1M # Copy kernel & ramdisk to BOOT partition device/brcm/rpi3/boot/* to p1:/ kernel/rpi/arch/arm/boot/zImage to p1:/ kernel/rpi/arch/arm/boot/dts/bcm2710-rpi-3-b.dtb to p1:/ kernel/rpi/arch/arm/boot/dts/overlays/vc4-kms-v3d.dtbo to p1:/overlays/vc4-kms-v3d.dtbo out/target/product/rpi3/ramdisk.img to p1:/ # HDMI_MODE : If DVI monitor does not work, try followings for p1:/config.txt hdmi_group=2 hdmi_mode=85 # How to put Android-TV launcher : https://github.com/android-rpi/device_brcm_rpi3/wiki#how-to-apply-android-tv-leanback-launcher