How Android finds OpenGL libraries, and the death of egl.cfg

Everybody who works on Android platform development knows that the vendor OpenGL libraries are located using information in egl.cfg. As of Android Kit Kat 4.4, they are out of date. Read on to find out why.

The OpenGL libraries

Android uses OpenGL ES to process 3D graphical functions and EGL to map them to a physical display. OpenGL ES is implemented in

/system/lib/libGLESv1_CM.so
/system/lib/libGLESv2.so
/system/lib/libGLESv3.so

The last one is optional, since Jelly Bean 4.3, and is for devices that support OpenGL ES 3.0. If it exists, it is a symlink to /system/lib/libGLESv2.so

EGL is implemented in

/system/lib/libEGL.so

These are just shim libraries. They call down to vendor supplied libraries that use the platform GPU do the real work. The library loader code is in frameworks/native/opengl/libs/EGL/Loader.cpp

Hardware accelerated graphics is a requirement for Android devices (since ICS 4.0).

Locating the vendor OpenGL libraries - past

Begin by looking at /system/lib/egl/egl.cfg, which contains something like this (from a Nexus 5 running KK 4.4)

0 0 android
0 1 adreno

The first number is the display ID, which is always 0: Android only supports OpenGL on the primary display. The second number is the implementation number. The OpenGL library loader tries the one with the highest number first and falls back to lower ones until it either succeeds or fails altogether. The text part is called the tag and is used to construct the name of the library. So in the case that the tag is “adreno” the libraries are

libEGL_adreno.so
libGLESv1_CM_adreno.so
libGLESv2_adreno.so

All three can be combined into a single library named libGLES_adreno.so. They are located in either /vendor/lib/egl or /system/lib/egl.

The idea of the line with the tag “android” is if the adreno libraries are not present the default OpenGL library, libGLES_android.so, will be loaded. This is a software OpenGL renderer also known as “Pixel Flinger”

At least, all the above is the theory: in fact neither the display ID nor the implementation numbers have been checked since JB 4.1: any old thing would do. And the tag “android” is assumed so the fallback to android is automatic. So the egl.cfg could (and should) have been written as

0 0 adreno

Locating the vendor OpenGL libraries – present

Now, in Kit Kat 4.4, the OpenGL loader code has been cleaned up a bit. It no longer reads egl.cfg. I repeat, egl.cfg is redundant and should no longer be placed in /system/lib/egl. So, that file you find on a Nexus 5 running Kit Kat 4.4: just delete it.

The new rules for loading the libraries are

1. Try to load files named
libGLES.so, or:
libEGL.so, libGLESv1_CM.so, libGLESv2.so
from /vendor/lib/egl or /system/lib/egl

2. For compatibility with the old naming scheme, also try to load files named
libGLES_*.so, or:
libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so
from /vendor/lib/egl or /system/lib/egl

The android “Pixel Flinger” fallback is gone altogether unless running in the emulator (system property ro.kernel.qemu = 1), in which case android is assumed.

Conclusion

This makes life simpler, and means that people working at the platform level can find the libraries a little more easily. It also means that a lot of readmes and howtos are out of date...

Want to know more about Android?

I have two training courses that will help you:
Android porting: http://www.2net.co.uk/training/android-porting
Android Internals: http://2net.co.uk/training/android-internals