Build and Evaluate Android TV on HiKey

The objective of this page is to share the instructions to build and evaluate Android TV on 96boards.org's open HiKey development platform.

What has been done so far

* Based on Linaro's RLCR release, we have added few patches to enable Android TV features for Hikey.

* The source manifest also pulls https://github.com/googlesamples/androidtv-sample-inputs Sample Inputs project.

* The sample inputs projects and it's dependencies are built using gradle scripts.

* The pre-built snapshot images can be pulled from http://snapshots.linaro.org/android/android-tv-hikey-n/. Note: For bootloader firmware, please use https://builds.96boards.org/snapshots/reference-platform/components/uefi/latest/release/hikey/.

* These images work on Lemaker's version of Hikey platform.

HOW TO Establish build environment

Kindly refer to Google provided instructions to setup the build environment for Android

https://source.android.com/source/initializing

Before doing repo init or repo sync kindly install few other host dependencies by executing the below command.

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip vim-common python-parted python-yaml wget uuid-dev python-mako u-boot-tools bc acpica-tools python-wand python-crypto mtools liblz4-tool

HOW TO Download the sources

Instructions to clone the sources are :

repo init -u https://android-git.linaro.org/git/platform/manifest.git -b android-7.1.1_r28 -g "default,-non-default,-device,hikey,fugu"
cd .repo
git clone https://android-git.linaro.org/git/platform/manifest.git -b linaro-nougat-tv local_manifests
cd -
repo sync -j16
./android-patchsets/hikey-tv
./android-patchsets/NOUGAT-RLCR-PATCHSET
./android-patchsets/hikey-optee-n
./android-patchsets/hikey-optee-4.9
./android-patchsets/hikey-n-workarounds
./android-patchsets/get-hikey-blobs

WARNING: If you run repo sync again at any time in the future to update all the repos, by default all the patches above would be discarded, so you'll have reapply them again before rebuilding!

wget http://snapshots.linaro.org/android/binaries/hikey/20160113-members-only/vendor.tar.bz2
tar -xvf vendor.tar.bz2

SETTINGS APP CRASH IN DEFAULT LAUNCHER

NOTE : The settings app crashes with default Android launcher when Android is configured for TV.

To get a working settings app, we recommend you to use LeanbackLauncher. The steps are as given below:

From this link https://developers.google.com/android/drivers#fugu download the latest launcher for TV from Google.

Example : Download https://dl.google.com/dl/android/aosp/google-fugu-lrx21m-b6038c1e.tgz

In Android source directory

tar -xzvf google-fugu-lrx21m-b6038c1e.tgz
./extract-google-fugu.sh # ACCEPT THE LICENSE

The LeanbackLauncher will be built as part of Android and Android would boot with this launcher.

HOW TO Build the sources

source build/envsetup.sh
lunch hikey-userdebug

** Build for 8GB flash Hikey

make -j16 TARGET_BUILD_FOR_TV=true TARGET_BUILD_KERNEL=true  CFG_SECURE_DATA_PATH=y

** Build for 4GB flash Hikey

make -j16 TARGET_BUILD_FOR_TV=true TARGET_USERDATAIMAGE_4GB=true TARGET_BUILD_KERNEL=true  CFG_SECURE_DATA_PATH=y
source build/envsetup.sh

[Build Live Tv Launcher]

tapas LiveTv arm64
make LiveTv
cp -r out/target/product/generic_arm64/system/priv-app/LiveTv/ out/target/product/hikey/system/priv-app/
mkdir -p apps/
cd apps/

NOTE : You should have Android SDK tools installed in your system, if not then please follow these steps one time, need not repeat these for every build :

# Look for the latest version of the tools here https://developer.android.com/studio/index.html and give the corresponding name of the zip file for wget
wget https://dl.google.com/android/repository/tools_r25.2.3-linux.zip
unzip tools_r25.2.3-linux.zip
(while :; do   echo 'y';   sleep 2; done) | tools/android update sdk --no-ui
export ANDROID_HOME=$PWD
mkdir -p /home/<your user name>/.android/
echo "count=0" > /home/<your user name>/.android/repositories.cfg

# List all build tools and install the required ones
./tools/android list sdk --all
./tools/android update sdk -u -a -t 47
./tools/android update sdk -u -a -t 15
./tools/android update sdk -u -a -t 8
./tools/android update sdk -u -a -t 6
./tools/android update sdk -u -a -t 7

If you have SDK installed previously then discard skip the steps above and continue as below

export ANDROID_HOME=<path to sdk>
echo "count=0" > $HOME/.android/repositories.cfg
rm -rf ExoPlayer androidtv-sample-inputs

Building apps and dependencies

androidtv-sample-inputs

git clone https://github.com/googlesamples/androidtv-sample-inputs
cd androidtv-sample-inputs/
sed -i "s/23.0.3/25.0.2/g" app/build.gradle library/build.gradle
./gradlew assembleDebug
cp app/build/outputs/apk/app-debug.apk ../../out/target/product/hikey/data/app/
cd -

ExoPlayer

git clone https://github.com/google/ExoPlayer
cd ExoPlayer
sed -i "s/23.0.3/25.0.2/g" build.gradle
./gradlew assembleDebug
cp ./demo/buildout/outputs/apk/demo-withExtensions-debug.apk  ../../out/target/product/hikey/data/app/
cd -

Tested with:

1b66908f7d79b6891d8d99705470797640457e72 (r2.6.0 + 1 commit)

2b20780482a9c6b07416bcbf4de829532859d10a (r2.6.1)

How to enable OPTEE support

1. Use Pre-built UEFI firmware: Download fip.bin here

Replace the firmware by following commend:

$ fastboot flash fastboot fip.bin

2. Build UEFI firmware manually:

$ cd device/linaro/hikey/bootloader/
$ make TARGET_TEE_IS_OPTEE=true
$ cd -

find the fip.bin at out/dist/

Preparing Images

# Compress images

cd out/target/product/hikey
../../../host/linux-x86/bin/make_ext4fs -s -T -1 -S root/file_contexts -L data -l 5588893184 -a data userdata.img data
../../../host/linux-x86/bin/make_ext4fs -s -T -1 -S root/file_contexts.bin -L system -l 1610612736 -a system system.img system system

Build UEFI bootloader with OP-TEE

cd device/linaro/hikey/bootloader
make TARGET_TEE_IS_OPTEE=true

Enable adb over usb

Boot the device. On serial console:

su
setprop sys.usb.configfs 1
stop adbd
start adbd

Submit Code changes

* Developers working on AOSP TV will have to implement the features and push patches using Gerrit. Details on how to use Gerrit is here, https://wiki.linaro.org/Platform/Android/Gerrit

* To post patches against Android's existing projects - Submit the patch to gerrit for review and include the patch in hikey-tv patchset: https://android-git.linaro.org/android-patchsets.git/tree/hikey-tv

* The file "hikey-tv" should contain all the patches related to hikey-tv configuration. We can also have a tv-patchsets file which will contain Android TV specific patches that one wishes to include.

* To post patches that introduces an all new project then ask Systems team to create a project repository and then post the patches against this repository.

Q&A & Notes

1. Q: I cannot pass the WV CDM Security L1 check and always falling back to L3 when using Exoplayer.

A: Check the /dev/tee* device nodes persission.

ex:

# chmod 777 /dev/tee* 

LHG/Build-AndroidTV-For-Hikey (last modified 2019-02-15 02:54:39)