B4ACarApp is a wrapper for Google's
Android for Cars App Library (androidx.car.app 1.7.0). It lets you build Android Auto apps entirely in B4A:
no Java, no inline Java, no JavaObject.
Android Auto does not display B4A layouts. Your app provides
templates (list, grid, pane, message) and Android Auto renders them on the car screen. The Car App Library requires subclassing CarAppService, Session and Screen, which B4A cannot do. B4ACarApp provides generic Java classes that forward everything to your B4A code as regular events.
Features (v0.1 beta)
- List, grid, pane and message templates
- Clickable rows, rows with icons, rows with toggles, header and footer action buttons
- Screen navigation: Push, Pop, PopToRoot, PopTo(Marker)
- Screen lifecycle events (Resume / Pause / Destroy), for example to start and stop a timer
- Car screen toasts
- Works when Android Auto launches the app directly: the B4A module (Starter by default) is started automatically, and a "Loading..." screen is shown until it is ready
Requirements
- B4A 14.2+ with an up-to-date AndroidX SDK (tested with Android SDK 36)
- minSdkVersion 24
- The two Car App Library AAR files from Google Maven, copied (unmodified) into your Additional Libraries folder and renamed as follows:
app-1.7.0.aar -> car-app-1.7.0.aar
app-projected-1.7.0.aar -> car-app-projected-1.7.0.aar
Installation
1. Copy B4ACarApp.jar, B4ACarApp.xml and the two AAR files into your Additional Libraries folder.
2. In the Main module:
#AdditionalJar: car-app-1.7.0.aar
#AdditionalJar: car-app-projected-1.7.0.aar
#AdditionalJar: androidx.arch.core:core-common
#AdditionalJar: androidx.arch.core:core-runtime
#AdditionalJar: androidx.lifecycle:lifecycle-common
#AdditionalJar: androidx.lifecycle:lifecycle-runtime
3. In the Manifest Editor, add
a single Android Auto block (a duplicated service prevents the app from showing up):
CreateResource(xml, automotive_app_desc.xml,
<automotiveApp>
<uses name="template"/>
</automotiveApp>
)
AddApplicationText(
<service
android:name="fr.fiveaces.carapp.B4ACarAppService"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService"/>
<category android:name="androidx.car.app.category.POI"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
<meta-data
android:name="androidx.car.app.minCarApiLevel"
android:value="1"/>
<meta-data
android:name="b4a.car.module"
android:value="starter"/>
)
- category: POI, IOT, NAVIGATION, WEATHER, CHARGING, PARKING... Google checks it at Play Store review.
- b4a.car.module: name (lower case) of the B4A service module that calls CarApp.Initialize. Default: starter.
Minimal example (Starter service)
Sub Process_Globals
Public Car As CarApp
Private Session As CarSession
Private Home As CarScreen
End Sub
Sub Service_Create
Car.Initialize("Car")
End Sub
'Raised each time the phone connects to the car: return the root screen
Sub Car_CreateScreen (NewSession As CarSession) As Object
Session = NewSession
Home.Initialize(Session, "Home")
Return Home
End Sub
'Raised each time Android Auto needs the screen content
Sub Home_GetTemplate As Object
Dim t As CarListTemplate
t.Initialize("HomeList", "My bike")
t.AddRow("Speed", "42 km/h", "speed")
t.AddToggleRow("Heated grips", "", False, "grips")
Return t.Build
End Sub
Sub HomeList_ItemClick (Tag As Object)
Session.ShowToast("Clicked: " & Tag, False)
End Sub
Sub HomeList_ToggleChanged (Tag As Object, Checked As Boolean)
Log(Tag & " = " & Checked)
End Sub
To refresh live data, update your variables and call
Home.Invalidate: GetTemplate will be raised again.
Testing
Important: on a real head unit (car, aftermarket head unit, Android Auto tablet), a Car App Library app only shows up if it was
installed by Google Play. The Android Auto "Unknown sources" developer option is not enough.
- Desktop Head Unit (DHU) - day-to-day development with the Debug APK installed by B4A: enable Android Auto developer mode (tap "Version" 10 times), menu > Start head unit server, then on the PC: adb forward tcp:5277 tcp:5277 and run desktop-head-unit.exe. Wireless debugging (adb pair / adb connect) also works.
- Real car: build a signed Release APK > Play Console > Internal app sharing > upload > open the link on the phone. Internal app sharing must first be enabled in the Play Store settings (tap the Play Store version 7 times, then Settings > General > Internal app sharing).
Debug builds accept any Android Auto host. Release builds use Google's official host allow-list.
Android Auto rules to keep in mind
- The number of list rows is limited while driving (often 6). The library truncates automatically.
- Invalidate with the same template type and title counts as a refresh. Pushing a screen with a different template counts as a "step" (max 5 per task, reset when going back to the root screen).
- Pane and message: 2 actions max. Grid: every item needs an icon.
- Everything runs on the main thread: keep GetTemplate fast.
Reference
CarApp - entry point
- Initialize (EventName As String) - call it in Service_Create of the module declared in b4a.car.module
- IsReady As Boolean (read-only) - True once Initialize has been called
Events:
- CreateScreen (Session As CarSession) As Object - return the root CarScreen
CarSession - current Android Auto session (one per car connection)
- Push (Screen As CarScreen) - show a new screen on top of the current one
- Pop - go back to the previous screen
- PopToRoot - go back to the root screen
- PopTo (Marker As String) - go back to the screen with this Marker
- ScreenCount As Int (read-only) - number of screens in the stack
- ShowToast (Text As String, LongDuration As Boolean) - short message on the car screen
- CarApiLevel As Int (read-only) - Car App API level negotiated with the host
- FinishCarApp - close the app on the car side
CarScreen - one Android Auto screen
- Initialize (Session As CarSession, EventName As String)
- Invalidate - ask Android Auto to refresh the screen (raises GetTemplate)
- Finish - remove this screen from the stack
- Marker As String - marker used by CarSession.PopTo
- Tag As Object - free to use
Events:
- GetTemplate As Object - return xxxTemplate.Build
- Resume - the screen is visible
- Pause - the screen is hidden
- Destroy - the screen was removed from the stack
CarListTemplate - list of rows
- Initialize (EventName As String, Title As String)
- AddRow (Title As String, Text As String, Tag As Object) - clickable row
- AddRowWithIcon (Title As String, Text As String, Icon As Bitmap, Tag As Object)
- AddInfoRow (Title As String, Text As String) - non-clickable row
- AddToggleRow (Title As String, Text As String, Checked As Boolean, Tag As Object)
- AddAction (Title As String, Tag As Object) - header button (2 max)
- ShowBackButton As Boolean - back arrow in the header (secondary screens)
- Loading As Boolean - show a progress indicator instead of the list
- EmptyMessage As String - text shown when the list is empty
- Build As Object
Events:
ItemClick (Tag As Object),
ToggleChanged (Tag As Object, Checked As Boolean),
ActionClick (Tag As Object)
CarGridTemplate - grid of icons
- Initialize (EventName As String, Title As String)
- AddItem (Title As String, Text As String, Icon As Bitmap, Tag As Object) - the icon is mandatory, Text can be empty
- AddAction (Title As String, Tag As Object)
- ShowBackButton As Boolean
- Loading As Boolean
- Build As Object
Events:
ItemClick (Tag As Object),
ActionClick (Tag As Object)
CarPaneTemplate - information pane, ideal for live values
- Initialize (EventName As String, Title As String)
- AddRow (Title As String, Text As String)
- AddAction (Title As String, Tag As Object) - bottom button (2 max)
- ShowBackButton As Boolean
- Loading As Boolean - an empty pane automatically switches to loading
- Build As Object
Events:
ActionClick (Tag As Object)
CarMessageTemplate - simple message (alert, confirmation, about...)
- Initialize (EventName As String, Title As String, Message As String)
- AddAction (Title As String, Tag As Object) - 2 max
- Icon As Bitmap (write-only)
- ShowBackButton As Boolean
- Loading As Boolean
- Build As Object
Events:
ActionClick (Tag As Object)
Roadmap
- Sectioned lists, SearchTemplate, LongMessageTemplate
- Modern Header API (Car API 7+)
- Session start / end events
- NavigationTemplate with map surface (NAVIGATION category)
- Android Automotive OS variant
Attached: the library (jar + xml), the Java sources, and a demo project (3 screens: live data with a timer, settings with toggles, about message).
Version history
v0.1 (December 2026) - first public beta