[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples/Code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Android for Cars - Jetpack Migration Guide
The Android for Cars App Library is now part of Jetpack!
Migrating to Jetpack provides a number of benefits, including giving you more
visibility into our feature development, and providing API consistency with
other Jetpack libraries.
As part of this move to Jetpack, we have made a number of changes to the API to
be consistent with the rest of the Android ecosystem. To help you migrate any
apps you have already built with the closed source version of the Car App
Library, we have compiled this guide, which describes the changes in detail and
provides instructions to migrate your app to the new library.
AndroidManifest Changes
In your app’s AndroidManifest.xml, replace the following closed source library
instances with their Jetpack library equivalents, wherever applicable:
The namespace of the library has been changed from com.google.android.libraries.car.app to androidx.car.app.
Replace all your library imports from com.google.android.libraries.car.app.* to androidx.car.app.*
CarAppService and Session
We have decoupled the lifecycle of the host connection to your app from
CarAppService to a new
Session class. The CarContext
and Screen creation logic has now been
moved to Session.
One of the main entry point to your app, CarAppService#onCreateScreen(Intent)
has been replaced with CarAppService.onCreateSession.
In essence, a number of methods that were previously in CarAppService are now
in the Session class. Refer to the following tables for a summary and
to the class-level documentation of Session
for more details.
In the simplest form, your app can return a Session instance like so if your
app does not have any logic that deal with the lifecycle of the connection:
@Override
@NonNull
public Session onCreateSession() {
return new Session() {
@Override
@NonNull
public Screen onCreateScreen(@Nullable Intent intent) {
return new HelloWorldScreen(getCarContext());
}
};
}
Builder Constructors
We are moving away from the model where we provide static builders for creating
various data objects. Instead we expose the builder constructors as public
methods directly. For example:
Pane.Builder paneBuilder = Pane.builder();
has become:
Pane.Builder paneBuilder = new Pane.Builder();
Builder Reusability
We are moving away from the model where we explicitly support builders to be
reused. Builder methods that allow your app to clear some previously-set data
are no longer available. For example, the following (and other clear* methods)
have been removed:
ActionStrip.Builder.clearActions()
New GridItem and GridTemplate
The Jetpack library comes with a new GridTemplate
that presents a list of GridItem
in a grid format. For details and usage, please refer to the documentation of
GridTemplate.
Host validation
We have added mechanisms to allow your app to validate that a host connection
is from a trusted source (for example, Android Auto and Android Automotive OS).
A sample implementation for the abstract CarAppService.createHostValidator
method is as follows:
@Override
public HostValidator createHostValidator() {
if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
return HostValidator.ALLOW_ALL_HOSTS_VALIDATOR;
} else {
return new HostValidator.Builder(getApplicationContext())
.addAllowedHosts(androidx.car.app.R.array.hosts_allowlist_sample)
.build();
}
}
The following tables highlight the rest of the changes we have done across
the library (such as renaming existing or adding additional APIs). Note that
this list is not exhaustive but provides insights to the categories of changes
we have done to the library.
static int TYPE_ROUNDABOUT_ENTER_CW static int TYPE_ROUNDABOUT_EXIT_CW static int TYPE_ROUNDABOUT_ENTER_CCW static int TYPE_ROUNDABOUT_EXIT_CCW static int TYPE_FERRY_BOAT_LEFT static int TYPE_FERRY_BOAT_RIGHT static int TYPE_FERRY_TRAIN_LEFT static int TYPE_FERRY_TRAIN_RIGHT
Removed
static int TYPE_ROUNDABOUT_ENTER static int TYPE_ROUNDABOUT_EXIT
The testing library is not yet available in the first beta release. Part of the
functionality the testing library offered for accessing fields set in models
through their builder classes is now available through the models' getters
themselves. The rest of the testing functionality will be available when the
testing library is released as part of Jetpack in the near future.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples/Code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.