C
Qt IF Android Vehicle Properties
The pre-built Qt::IfAndroidVehicleProperties module is deprecated and will be removed in Qt 7. Define your own .qface and .yaml files and use qt_ifcodegen_extend_target() to generate the integration code for your specific Android version. See How it Works below for the recommended approach.
Qt for Android Automotive provides a code generation approach for accessing Android Automotive Vehicle Properties. Rather than shipping a fixed set of pre-built libraries, Qt ships the Qt IF Generator Extensions — a set of Jinja2 templates and Java infrastructure — that generate the required C++ and Java glue code from a customer-defined interface description.
This means each customer defines exactly the vehicle properties their application needs, maps them to the Android VHAL property IDs for their target Android version, and generates the integration code at their own build time. As Android evolves and new VHAL properties are introduced, customers can adapt by updating their own .qface and .yaml files, without needing a Qt for Android Automotive update.
How it Works
The interface to vehicle properties is defined by two customer-owned files:
- A
.qfacefile — defines the Qt-side interfaces, properties, and types using the Qt Interface Framework Interface Definition Language. - A
.yamlfile — maps each property to an Android VHAL property ID, zone configuration, and required Android permissions.
At build time, qt_ifcodegen_extend_target() processes these files through Qt's generic templates to generate:
- A C++ frontend library — the Qt IF feature classes for your properties.
- A JNI backend plugin — the C++ and Java code that calls Android's
CarPropertyManagervia JNI. - A QML plugin — exposes the frontend types to QML (optional).
Defining Your Interface
Create a .qface file defining the vehicle interfaces your application needs. Interface names, property names, and types are entirely up to you:
module MyVehicleProperties 1.0
interface MyHVAC {
bool acOn;
real temperatureSet;
int fanSpeed;
}
interface MyDriveInfo {
real vehicleSpeed;
bool parkingBrakeOn;
}Create a matching .yaml file that maps each property to its Android VHAL property ID and zone:
MyHVAC.acOn:
config_android_automotive:
vhalPropertyId: HVAC_AC_ON
vhalAreaIds: [VehicleAreaSeat.ROW_1_LEFT]
MyHVAC.temperatureSet:
config_android_automotive:
vhalPropertyId: HVAC_TEMPERATURE_SET
vhalAreaIds: [VehicleAreaSeat.ROW_1_LEFT, VehicleAreaSeat.ROW_1_RIGHT]
MyHVAC.fanSpeed:
config_android_automotive:
vhalPropertyId: HVAC_FAN_SPEED
MyDriveInfo.vehicleSpeed:
config_android_automotive:
vhalPropertyId: PERF_VEHICLE_SPEED
MyDriveInfo.parkingBrakeOn:
config_android_automotive:
vhalPropertyId: PARKING_BRAKE_ONCMake Setup
Structure your project with a frontend library, a JNI backend plugin, and optionally a QML imports module. The pattern mirrors the HVAC Control example.
Frontend library — generates the Qt IF C++ types from your .qface:
find_package(Qt6 COMPONENTS Core Qml Quick InterfaceFramework)
set(target_name MyVehiclePropertiesFrontend)
qt_add_library(${target_name} SHARED)
qt6_ifcodegen_extend_target(${target_name}
IDL_FILES path/to/myvehicle.qface
TEMPLATE frontend
)
target_link_libraries(${target_name} PRIVATE
Qt::Core Qt::Qml Qt::Quick
Qt::InterfaceFramework Qt::InterfaceFrameworkPrivate
)JNI backend plugin — generates the Android Car API integration:
find_package(Qt6 COMPONENTS Core CorePrivate InterfaceFramework)
set(target_name MyVehiclePropertiesJniPlugin)
qt_add_plugin(${target_name} PLUGIN_TYPE interfaceframework)
set_target_properties(${target_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qtif"
)
qt6_ifcodegen_extend_target(${target_name}
IDL_FILES path/to/myvehicle.qface
TEMPLATE backend_android_carapi_jni
MODULE_NAME MyVehicleProperties
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(${target_name} PRIVATE
Qt::Core Qt::CorePrivate Qt::InterfaceFramework
MyVehiclePropertiesFrontend
)Application target — wire the frontend and backend into the app:
qt_add_executable(my_app main.cpp)
add_dependencies(my_app MyVehiclePropertiesFrontend MyVehiclePropertiesJniPlugin)
target_link_libraries(my_app PRIVATE
Qt::Core Qt::Quick Qt::InterfaceFramework
)
set_property(TARGET my_app APPEND PROPERTY QT_ANDROID_EXTRA_LIBS
"${frontend_bin_dir}/libMyVehiclePropertiesFrontend_${CMAKE_ANDROID_ARCH_ABI}.so")
set_property(TARGET my_app APPEND PROPERTY QT_ANDROID_EXTRA_PLUGINS
"${backend_bin_dir}/qtif")Android Permissions
Declare the Car API permissions your properties require in your AndroidManifest.xml. For example, for HVAC and drive info:
<uses-permission android:name="android.car.permission.CONTROL_CAR_CLIMATE"/>
<uses-permission android:name="android.car.permission.CAR_SPEED"/>
<uses-permission android:name="android.car.permission.CAR_POWERTRAIN"/>Add only the permissions for the specific properties your application uses.
QML Usage
If you generate a QML plugin (using the qmlplugin template), add the import in your QML file using the URI derived from your module name:
import MyVehicleProperties
MyHVAC {
id: climateControl
}
Button {
text: climateControl.acOn ? "AC ON" : "AC OFF"
onClicked: climateControl.acOn = !climateControl.acOn
}Known Issues and Limitations
- To deploy an application using this module, the following additional steps are needed:
- Enable AndroidX in
gradle.propertiesby addingandroid.useAndroidX=true - Add
android.car.jarto your APK'sandroid/libs/directory
- Enable AndroidX in
- Static vehicle properties do not react to changes in the emulator. Static properties are set once during manufacturing and Android Automotive does not broadcast changes. See AOSP: Vehicle Properties source code for the full list of static properties.
See also Qt for Android Automotive, Qt Interface Framework, and Qt IF Generator Extensions.
Available under certain Qt licenses.
Find out more.