[ Web Proxy ]
URL:
Viewing: https://source.android.com/docs/core/architecture/hidl-cpp/packages [Back]  [Original]

Packages  |  Android Open Source Project Skip to main content
Android Open Source Project [Android Open Source Project]

Packages Stay organized with collections Save and categorize content based on your preferences.

Note: This section uses sample .hal files to illustrate how HIDL language constructs map to C++.

With few exceptions, HIDL interface packages are located in hardware/interfaces or the vendor/ directory. The hardware/interfaces top-level maps directly to the android.hardware package namespace; the version is a subdirectory under the package (not interface) namespace.

The hidl-gen compiler compiles the .hal files into a set of a .h and .cpp files. From these autogenerated files a shared library that client/server implementations link against is built. The Android.bp file that builds this shared library is autogenerated by the hardware/interfaces/update-makefiles.sh script. Every time you add a new package to hardware/interfaces, or add/remove .hal files to/from an existing package, you must rerun the script to ensure the generated shared library is up-to-date.

For example, the IFoo.hal sample file should be located in hardware/interfaces/samples/1.0. The sample IFoo.hal file creates an IFoo interface in the samples package:

package android.hardware.samples@1.0;
interface IFoo {
    struct Foo {
       int64_t someValue;
       handle  myHandle;
    };

    someMethod() generates (vec<uint32_t>);
    anotherMethod(Foo foo) generates (int32_t ret);
};

Generated files

Autogenerated files in a HIDL package are linked into a single shared library with the same name as the package (for example, android.hardware.samples@1.0). The shared library also exports a single header, IFoo.h, which can be included by clients and servers. Using the hidl-gen compiler with the IFoo.hal interface file as an input, binderized mode has the following autogenerated files:

Files
generated by compiler [Files generated by compiler]

Figure 1. Files generated by compiler.

The files are structured similarly to the files generated by aidl-cpp (for details, see "Passthrough mode" in the HIDL Overview). The only autogenerated file that is independent of the RPC mechanism used by HIDL is IFoo.h; all other files are tied to the HwBinder RPC mechanism used by HIDL. Therefore, client and server implementations should never directly refer to anything other than IFoo. To achieve this, include only IFoo.h and link against the generated shared library.

Note: HwBinder is only one possible transport; new transports might be added in the future.

A client or server that uses any interface in a package must include the shared library of that package in one (1) of the following locations:

Additional libraries you might need to include:

libhidlbase Includes standard HIDL data types. Starting in Android 10, this also contains all of the symbols previously in libhidltransport and libhwbinder.
libhidltransport Handles the transport of HIDL calls over different RPC/IPC mechanisms. Android 10 deprecates this library.
libhwbinder Binder-specific symbols. Android 10 deprecates this library.
libfmq Fast Message Queue IPC.

Namespaces

HIDL functions and types such as Return<T> and Void() are declared in namespace ::android::hardware. The C++ namespace of a package is determined by the package name and version. For example, a package mypackage with version 1.2 under hardware/interfaces has the following qualities:

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-07-13 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-07-13 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page