Android HIDL and Project Treble

One of the problems in Android is the fact that when a new version is released only a few devices can be updated. Actually, if you want to enjoy the latest version, you need to buy a new smartphone every 6 months. Google solution is the Project trebel that separates the vendor implementation from the Android OS framework via a new vendor interface


HAL interface definition language used to describe the interface between the framework and the vendor. All hardware interfaces are located in hardware/interfaces in .hal files

Let’s go over simple example

Create all the path


Create a hal file in ISimphw.hal in  hardware/interfaces/simple/2.0

Generate the HAL files

To generate the HAL files you need to use the hidl-gen tool run:

And to update all makefile (, Android.bp) run:

Now add 2 empty files to hardware/interfaces/simple/2.0/default:

  • android.hardware.simple@2.0-service.rc
  • service.cpp

Now the directory hardware/interfaces/simple should look like this:

Implementing the HAL shared object:

we need to add a new static function to return the service object (usually as a singleton)



Note that if you want to support pass-through mode, you need to uncomment the HIDL_FETCH_ISimphw function

In this example, we implemented the function as simple as possible (usually we will load the hardware module here)

The generated Android.bp file build a shared library with the implementation – android.hardware.simple@2.0-impl

Creating the Service

To host the library we need to create a simple executable:


We create an instance of our implementation, Create a thread pool for the binder and register the current process as a service

Note that the function regsiterAsService() is auto-generated by hidl-gen tool

To make this service run automatically add init file:


For testing purpose I set the security label to su , we need to set SE Linux rules (I wrote it in the init.te file):

To tell the build system to build the service add the following to Android.bp (in directory default)

Add the following components to build/make/target/product/


Now build the ROM and run it, connect with adb and run ps -A to see all the hardware services:

The lshal tool list all the hardware services by categories:

Writing the Client

To use the service we will write a simple client application. Usually, it will be part of the Android framework written by Google. For example, if the generic framework wants to access the vibrator service:

In file  frameworks/base/services/core/jni/com_android_server_VibratorService.cpp

Add a new directory in device/generic/goldfish – simphaltest

Add the source and Android.bp files:


Add the client test to build/make/target/product/

Add hal entry to the Manifest.xml file of your device (device/generic/goldfish/Manifest.xml in this case)

Build the ROM again and test our service:


Tagged , ,

7 thoughts on “Android HIDL and Project Treble

  1. This is the best DEMONSTRATION of How to get a HAL going I have found, Unfortunately When following it through on OREO my service fails to load the impl library from the ‘HW’ dir, if I push the library up a level to the lib64, it is found. I see nearly all the other standard(or BSP) HALS are lOAded from ‘HW’ but I cant see what they have different. Whats the trick ?
    I get:
    “library “” not found”
    Although it is clearly there and it does load if I move it up to lib64

  2. What IDE to run the code?

  3. thanks a lot, works great. Required to update dev/*/* in Android.bp in root directory to dev/*/*/* to access the Android.bp created in device/generic/goldfish/simphaltest.

  4. hI,

    I tried steps given for “android.hardware.simple@2.0″ HIDL interface and thats worked. I like the simple steps/command to generate HIDL impl and HIDL service, it really gives the confidence for who are new into Android HAL framework.

    Thanks a lot.

    One more change is required to build HIDL impl lib, just add “2.0/default” into Android.bp to include default dir Android.bp


    subdirs = [


    As per hardware/interfaces/simple/2.0/default/Android.bp rule,

    name: “android.hardware.simple@2.0-impl”,
    relative_install_path: “hw”,
    proprietary: true,

    the impl lib should build at below location in vendor.img


    can check your HIDL package name ? from error it seems to be UPPER case string issue “library “” not found”

    and also check product packages should include in

    android.hardware.simple@2.0-impl \
    android.hardware.simple@2.0-service \

  5. it so good refference. thanks

  6. Hi
    I followed the steps given above but i am getting following error while trying to generate the HIDL files:

    ERROR: Unable to automatically import ‘android.hidl.base@1.0::IBase’ at /home/AOSP/hardware/interfaces/simple/2.0/ISimple.hal
    ERROR: Could not parse android.hardware.simple@2.0::ISimple Aborting

  7. hello.
    i have a question.
    i dont make files about simple directory.
    i try to execute hardware/interfaces/
    and i got a message about this.
    Updating android.hardware.simple@2.0

    but in the directory of simple/2.0/
    dont find a file.

Leave a Reply

Your email address will not be published. Required fields are marked *