You may have heard about ​​libhybris​​, a library that cleverly loads Android HW adaptations and convert calls from bionic to glibc. One of the greatest achievement of this library is to allow Android GPU drivers to be used with Linux, and is notably used by Canonical, although they did not write it, for Ubuntu 14.04 which will be compatible with any recent Android smartphones or tablets.

One way to get started with libhybris is to ​​port a device to Ubuntu Touch​​​, but this may take a while. However, I’ve found a faster and easier way to play with libhybris thanks to Martin Brook (vgrade) who wrote a tutorial on how to ​​use libhybris with Mer​​​ on the Cubieboard. ​​Mer​​​ is an open source mobile Linux distribution powered by Qt/QML and HTML5, that’s born from the ashes of Meego, and is now used in the upcoming ​​Sailfish OS​​.

How to Use Libhybris and Android GPU Libraries with Mer (Linux) on the Cubieboard_linux

Qt5 Cinematic Experienced Rendered at 25 fps in Cubieboard via Android GPU Drivers in Linux Thanks to libhybris


You’ll need to follow 4 main steps:

  • Build Android
  • Build a minimal Mer image
  • Install Libhybris
  • Run demos

I’ll skip the Mer image build since Martin has provided a binary image. I’ll use a build machine running Ubuntu 12.04.2 LTS. You should make sure the ​​build environment is setup correctly​​​, you’ve installed ​​repo​​, and that it’s in your path. I’ll use the Cubieboard (1GB RAM), but you may want to try other hardware platform, or Linux distribution as the instructions should be similar.

Build Android for the Cubieboard

This is basically following the instructions provided ​​here​​. First let’s code Android Jelly Bean (CyanogenMod) source code:

mkdir openbox && cd openbox repo init --no-repo-verify -u git://github.com/cubieboard/manifests -b cb -m jb.xml repo sync

1

2

3


mkdir openbox && cd openbox

repo init --no-repo-verify -u git://github.com/cubieboard/manifests -b cb -m jb.xml  

repo sync


repo sync may take quite a while depending on your Internet connection. It took 10 hours, after several attempts over three days… Once this is done, we’ll need to configure the build for the Cubieboard:

source build/envsetup.sh lunch

1

2


source build/envsetup.sh

lunch


Select Cubieboard (#4), and start the build:

make -j10


1



make -j10


The build initially failed with this error:

****************************** You have tried to change the API from what has been previously approved. To make these errors go away, you have two choices:    1) You can add "@hide" javadoc comments to the methods, etc. listed in the       errors above.    2) You can update current.txt by executing the following command:          make update-api       ^^^^^^^^^^^^^^^^^^       NO. NO. STOP BEING LAZY. SERIOUSLY.       DO NOT DO THIS in CM. THIS IS A LIE. IF YOU DO THIS I WILL HATE YOU.       USE OPTION #1.                     -Koush       To submit the revised current.txt to the main Android repository,       you will need approval. ******************************

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18


******************************

You have tried to change the API from what has been previously approved.


To make these errors go away, you have two choices:

   1) You can add "@hide" javadoc comments to the methods, etc. listed in the

      errors above.


   2) You can update current.txt by executing the following command:

         make update-api

      ^^^^^^^^^^^^^^^^^^

      NO. NO. STOP BEING LAZY. SERIOUSLY.

      DO NOT DO THIS in CM. THIS IS A LIE. IF YOU DO THIS I WILL HATE YOU.

      USE OPTION #1.

                    -Koush


      To submit the revised current.txt to the main Android repository,

      you will need approval.

******************************


So I shamelessly typed “make update-api” to automatically update current.txt, and continued the build with “make -j10”. The build may also take quite a while depending on your computer performance and available RAM. This step was much faster than repo sync in my case, as it just took about 45 minutes in total.

The Android build is now completed, but we need still to patch Bionic library, and rebuild:

cd bionic wget  http://pastie.org/pastes/7649385/download -O bionic_libhybris.patch patch -p1 < bionic_libhybris.patch cd .. make -j10

1

2

3

4

5


cd bionic

wget  http://pastie.org/pastes/7649385/download -O bionic_libhybris.patch

patch -p1 < bionic_libhybris.patch

cd ..

make -j10


Now let’s tar Android’s system directory as we’ll need to copy the will have the patched bionic library plus all the android libs (EGL, GLESv2, RIL etc):

pushd out/target/product/cubieboard/system/ tar cjvf ../../../../../cubie_android_system.tar.bz2 . popd

1

2

3


pushd out/target/product/cubieboard/system/

tar cjvf ../../../../../cubie_android_system.tar.bz2 .

popd


Installing and Running Mer

Since we don’t build the image ourself, this step is rather easy, as we just need to download the image, and dump it to a micro SD card.

​wget ftp://5.9.162.110/nemo/cubieboard/tablet/cubieboard/mer/testing/armv7hl/weekly/nemo-cubieboard-tablet-cubieboard-mer-testing-armv7hl-weekly-20130511-1516-mmcblk0p.raw.bz2
bzip2 -d nemo-cubieboard-tablet-cubieboard-mer-testing-armv7hl-weekly-20130511-1516-mmcblk0p.raw.bz2​

Burn the image to a microSD card (4GB or greater):

sudo dd.sh if=nemo-cubieboard-tablet-cubieboard-mer-testing-armv7hl-weekly-20130511-1516-mmcblk0p.raw of=/dev/<sd_device> bs=1M sync

1

2


sudo dd.sh if=nemo-cubieboard-tablet-cubieboard-mer-testing-armv7hl-weekly-20130511-1516-mmcblk0p.raw of=/dev/<sd_device> bs=1M

sync


Where you need to replace <sd_device> by your actual SD card device such as “sdc”.

My 4GB microSD is slightly smaller than the image provided, so dd failed at the very end. But you can usually run the following 2 commands on the last partition (in this case ext4) in order to resize the partition, and fix any potential boot problems:

e2fsck -y /dev/sdc2 resize2fs  /dev/sdc2 +3300K

1

2


e2fsck -y /dev/sdc2

resize2fs  /dev/sdc2 +3300K


Interestingly, this time those commands failed, but I still inserted the microSD in my Cubieboard, and I was able to login successfully into Mer via the serial console as root (password: mer). You should also have access a terminal on the HDMI monitor.

We don’t want X to start anymore, so let’s disable it and restart the Cubieboard:

zypper rm uxlauncher reboot

1

2


zypper rm uxlauncher

reboot


If you’re using HDMI console, switch to VT2 (Ctrl+Alt+F2) before running the command.

Installing libhybris and Android system folder

Let’s log-in again via the serial console, or via VT2 on the HDMI monitor if this works for you, and install libhybris:

​zypper ar http://repo.merproject.org/obs/home:/sage:/libhybris/latest_armv7hl/home:sage:libhybris.repo
zypper in libhybris
zypper in libhybris-tests​

You may want to enlarge your terminal for the steps above, as the text goes over the window, and you have to answer some questions for the installation. The next step is to install Android’s system files to /system in the Cubieboard. Copy the files from the Linux PC to the Cubieboard:

scp cubie_android_system.tar.bz2 root@192.168.0.107:/


1



scp cubie_android_system.tar.bz2 root@192.168.0.107:/


and complete the install in the board:

mkdir system cd /system tar xjvf ../cubie_android_system.tar.bz2

1

2

3


mkdir system

cd /system

tar xjvf ../cubie_android_system.tar.bz2


The installation is now complete and it’s time to try it out.

Graphics Demos

To test whether libhybris is correctly installed run the following:

test_egl


1



test_egl


The only problem is that it did not work exactly as expected:

test_egl: test_egl.c:43: main: Assertion `eglChooseConfig((EGLDisplay) display, attr, &ecfg, 1, &num_config) == 1' fai. Aborted

1

2


test_egl: test_egl.c:43: main: Assertion `eglChooseConfig((EGLDisplay) display, attr, &ecfg, 1, &num_config) == 1' fai.

Aborted        


After a reboot, Cubieboard decided to boot Android from flash, so I tried to remove and re-insert the micro SD, and noooooooooo! The micro SD socket let me down and refuses to lock the card in place, so I’ll have to replace the slot which will take me few weeks since I have to order the thing.

So I count on you to let me know what has gone wrong. Thanks