Android Car Samples
repository·main·Indexed 19 days ago
https://github.com/android/car-samplesA collection of Android Studio projects providing practical examples for developing automotive applications. It includes samples for the Car App Library, compatible with Android Auto and Android Automotive OS (AAOS), as well as specialized AAOS samples like the Car Gear Viewer. The repository demonstrates the use of various UI templates, such as SectionedItemTemplate and MapWithContentTemplate, and provides guidance on building and running apps via Android Studio, the command line, the Desktop Head Unit (DHU), and the Automotive OS emulator.
What's inside android-car-samples
- This repository provides a collection of individual Android Studio projects designed to help developers build applications for automotive environments. The samples are organized based on the specific integration libraries they utilize.
Overview of the Navigation Sample
mainThe Navigation Sample is a demonstration of a turn-by-turn navigation application built using the Car App library. It uses fictitious locations and basic surface drawing to illustrate how to implement navigation-specific features and UI within the Car App ecosystem.Overview of the Showcase Sample
mainThe Showcase Sample is a demonstration application designed to showcase the various templates and features available within the Car App Library. Developers can use this sample to understand how to implement different UI templates and utilize the library's core capabilities in a real-world app context.Overview of Android Automotive OS (AAOS) samples
mainThis repository contains sample applications and libraries specifically designed for Android Automotive OS (AAOS), the Android-based infotainment system built into vehicles.
Important Note: The samples in this library are specialized for the automotive environment and currently only run on AAOS-compatible hardware or emulators.
Overview of AAOS Car Gear Viewer (Kotlin)
mainThe AAOS Car Gear Viewer (Kotlin) sample demonstrates how to connect to the Android Automotive OS (AAOS) Car API to monitor and display vehicle gear changes on an In-Vehicle Infotainment (IVI) screen.
Key technical details:
- It uses
CarPropertyManagerto subscribe to gear change events. - It updates the UI upon receiving valid change events.
- It logs error events received from the Car API.
- It requires Android P (API 28) or higher, though the sample specifically targets API 29+ for its SDK requirements.
- It uses
Understand the Car App Library integration
mainThe Car App Library is used to build specialized automotive applications such as navigation, parking, and charging apps. These applications are compatible with:
- Android Auto: Apps running on a phone connected to a car.
- Android Automotive OS: Apps running directly on the car's head unit.
Understand the car-lib integration
mainThecar-lib/samples are specifically designed for integration with Android Automotive OS.Build the Car Gear Viewer project
mainThe project uses the Gradle build system. You can build the project using the command line or Android Studio:
Using Gradle CLI:
./gradlew buildUsing Android Studio: Use the
Import Projectoption to open the project and let Android Studio manage the build process.Run Automotive Apps in the Automotive OS Emulator
mainTo test embedded automotive apps, use the Automotive OS emulator.
Requirements:
- Android Studio 4.2 or higher (Beta or Canary tracks may be required).
Steps:
- Follow the standard instructions to run an Automotive OS emulator.
- Follow the instructions to update the Template Host app.
Prerequisites for Car Gear Viewer
mainTo run or build the Car Gear Viewer sample, ensure you meet the following requirements:
- SDK: Android 10 SDK (API level 29) Revision 5 or newer.
- Hardware/Runtime: A device or emulator running Android Automotive OS P (API 28) or newer.
Run Mobile Apps in the Desktop Head Unit (DHU)
mainTo test mobile (projected) apps on your computer, use the Desktop Head Unit (DHU).
Steps:
- Enable Android Developer Settings on your device.
- Enable Unknown Sources in Android Auto.
- Run the DHU.
Note for Android Q users: If you cannot find the Android Auto app in the launcher, navigate to
Settings -> Apps & Notifications -> See all apps -> Android Auto -> Advanced -> Additional settings in the app.Build and Install Samples via Command Line
mainYou can assemble and install sample APKs using the Gradle wrapper and ADB.
1. Assemble APKs
First, open the project in Android Studio once to ensure the Gradle wrapper files are downloaded. Then run:
./gradlew :<sample_app>:<platform>:assembleExamples:
- Mobile:
./gradlew :showcase:mobile:assemble - Automotive:
./gradlew :showcase:automotive:assemble
Generated APKs are located in:
<sample_app>/<platform>/build/outputs/apk/debug.2. Troubleshooting SDK Location
If you encounter an
SDK location not founderror, create alocal.propertiesfile in the project root and add your SDK path:sdk.dir = <your android sdk directory path>3. Install via ADB
Once the APK is built, install it using:
adb install <path_to_sample_app_apk># Example: Assemble showcase mobile app ./gradlew :showcase:mobile:assemble # Example: Install the resulting APK adb install showcase/mobile/build/outputs/apk/debug/app-debug.apk- Mobile: