April 23, 2024

Android Automotive OS is getting extra recognition as automotive firms want to present their prospects with a extra tailor-made expertise. Right here we share our information to constructing the primary app for AAOS.

Earlier than you begin, learn our first article about AAOS and get to know our assessment to pay attention to what to anticipate. Let’s strive making a easy Hiya World app for android automotive. To get an IDE, go to Android Studio Preview | Android Developers and get a canary construct:

AAOS Hello World: How to Build Your First App for Android Automotive OS

Within the subsequent step, put together SDK, test and obtain the Automotive system picture in SDK supervisor. You will get any from api32, Android 9, or Android 10, however I don’t suggest the most recent one as it is extremely laggy and crashes lots proper now. There are additionally Volvo and Polestar photographs.

For these that you must add hyperlinks to SDK Replace Websites:



Begin a brand new challenge, go to File> New Undertaking and select automotive with no exercise

Android Automotive OS

A pleasant and clear challenge ought to be created, with none lessons: Go to construct.gradle and add the automotive app library into dependencies, refresh the challenge to make it get

AAOS Hello World

our new dependency:

implementation "androidx.automotive.app:app-automotive:1.2.0-rc01"

Let’s write some code, first our display class. Identify it as you need and make it lengthen Display class from android.automotive.app bundle and make it implement required strategies:

public class GrapeAppScreen extends Display 

   public GrapeAppScreen(@NonNull CarContext carContext) 

   public Template onGetTemplate() 
       Row row = new Row.Builder()
.setTitle("Thats our Grape App!").construct();

       return new PaneTemplate.Builder(
               new Pane.Builder()

That ought to create a easy display with our icon and title, now create one other class extending CarAppService from the identical bundle and as effectively make it implement the required strategies. From createHostValidator() methodology return a static one that permits all hostnames for the aim of this tutorial and return model new session with our display in onCreateSession(), cross CarContext utilizing Session class getCarContext() methodology:

public class GrapeAppService extends CarAppService 

   public GrapeAppService() 

   public HostValidator createHostValidator() 
       return HostValidator.ALLOW_ALL_HOSTS_VALIDATOR;

public Session onCreateSession() 
   return new Session() 
       public Display onCreateScreen(@Nullable Intent intent) 
           return new GrapeAppScreen(getCarContext());

Subsequent, transfer to AndroidManifest and add numerous options inside the primary manifest tag:

   android:required="true" />
   android:identify="android.software program.automotive.templates_host"
   android:required="true" />
   android:required="false" />
   android:required="false" />
   android:required="false" />

Contained in the Software tag add our service and exercise, don’t neglect minCarApiLevel as lack of this can throw an exception on app begin:


<meta-data android:identify="androidx.automotive.app.minCarApiLevel"

           <motion android:identify="androidx.automotive.app.CarAppService" />

       android:label="GrapeApp Starter"

           <motion android:identify="android.intent.motion.MAIN" />
           <class android:identify="android.intent.class.LAUNCHER" />
           android:worth="true" />

Now we are able to add our software to the gadget, confirm that you’ve an automotive emulator created, use automotive configuration, and hit run. The app is run in Google Automotive App Host, so if it’s your first software on this gadget, it could require you to get to the play retailer and get it.

That’s the way it appears to be like:

Build Your First App for Android Automotive OS

The very last thing, we’ll add a navigation button that can pop a Toast. Modify onGetTemplate() in Display class, add Motion and ActionStrip:

Motion motion = new Motion.Builder()
               () -> CarToast.makeText(getCarContext(), "Hiya!", CarToast.LENGTH_SHORT).present())
       .setTitle("Say hello!")

ActionStrip actionStrip = new 

Add it to PaneTemplate:

return new PaneTemplate.Builder(
       new Pane.Builder()
)       .setActionStrip(actionStrip)

That’s our HelloWorld app:

Now you may have the HelloWorld instance app up and working utilizing Automobile App Library. It takes care of displaying and arranging every thing on the display for us. The one accountability is so as to add screens and actions we want to have(and a little bit of configuration). Verify the Automobile app library to discover extra of what might be finished with it, mess around with creating your app, and positively test our weblog quickly for extra AAOS app creation content material.

Android Automotive OS