How to utilize Android Car API inside an app
Asked Answered
M

5

9

I want to test and (if possible) utilize Android Car API functionalities inside my Android app. Specifically, I need to be able to import classes under android.car.* package which can be seen here: https://developer.android.com/reference/android/car/packages.html

I also found the repo on Google Git: https://android.googlesource.com/platform/packages/services/Car/

How should I add this library as a dependency in my app?

Muscadel answered 12/3, 2019 at 16:3 Comment(0)
U
17

The library is now released as part of Android Q SDK in Android Studio. You need to

  1. update the SDK 29 to minor version 5 using SDK manager

  2. Update app module build.gradle include car-lib

    android {
         compileSdkVersion 29
         buildToolsVersion "29.0.3"
         ...
         useLibrary 'android.car'
    }
    
  3. API documentation is available here

Urbanity answered 8/8, 2020 at 23:51 Comment(4)
Where this lib came from: useLibrary 'android.car' if you compile standalone project, not a part of AOSP.Plebe
see #1, use SDK Manager in Android Studio.Urbanity
Doesn't work. Package android.car.Car still unavailable. Google as always cant provide normal guide.Pinot
This answer didn't work for me so here is how I achieved it https://mcmap.net/q/1128469/-how-to-utilize-android-car-api-inside-an-appReeta
A
5

Edit: This answer is outdated. Use the method in the accepted answer now that the tooling has been updated and the lib is part of the platform.

There's no prebuilt binary for android.car, but you can build it yourself by running mm in packages/services/Car/car-lib: https://android.googlesource.com/platform/packages/services/Car/+/refs/heads/master/car-lib/Android.bp#50

If your app has an .mk or .bp file, you can include the library like CarService does here: https://android.googlesource.com/platform/packages/services/Car/+/master/service/Android.mk#42

The library is mostly meant for OEMs though and not so much for third parties.

Antiworld answered 12/3, 2019 at 21:4 Comment(5)
Also found this in Google's issue tracker for some supporting info: issuetracker.google.com/issues/74386715Specific
make android.cardoes not work. how can I create android.car.jar from Android.bp?Muscadel
Sorry, I'll update the answer. If you run mm in packages/services/Car/car-lib it should install the android.car.jar into target/product/<product_name>/system/framework/android.car.jar.Antiworld
I'm getting the following error when I run mm or mma command: Couldn't locate the top of the tree. Try setting TOP.Muscadel
TOP or ANDROID_BUILD_TOP should be the root of the AOSP tree. I thought "source build/envsetup" would set that up though.Antiworld
R
2

This is how I achieved Car APIs (android.car.Car) for My Application

Note: You need to have AOSP code to achieve this solution

Step1. Go to your AOSP code base and run below mentioned commands

AOSP$ source build/envsetup.sh

AOSP$ lunch aosp_car_x86-userdebug

AOSP$ cd packages/services/Car/car-lib
AOSP$ mm

Once car-lib module is built successfully, Go to below mentioned path and copy classes.jar file

AOSP$ cd out/target/common/obj/JAVA_LIBRARIES/android.car_intermediates/

Copy that classes.jar file and paste in your projects libs folder (e.g. MyApp/app/libs)

right click on the classes.jar file in libs and select Add as Library option

OR

you can directly add implementation files('libs/classes.jar') in your dependencies in build.gradle (app) file

Hope this answer will help

Reeta answered 12/2, 2023 at 3:4 Comment(0)
T
0

For Linux you need to first set the environment and then build it:

. build/envsetup.sh

lunch aosp_car_x86-userdebug

make -j8
Tetracycline answered 11/2, 2021 at 9:3 Comment(0)
B
0

For those where https://mcmap.net/q/1128469/-how-to-utilize-android-car-api-inside-an-app doesn't work due to https://issuetracker.google.com/issues/234749386: here's how to incorporate the android.car.jar without the use of AOSP (it's in the SDK, but not found by Android Studio...):

  1. Locate the android.car.jar that corresponds to your app's compileSdk value. For instance for compileSdk=33, the jar can be found in $ANDROID_SDK_ROOT/platforms/android-33/optional/android.car.jar
  2. Copy it to the app/libs/ directory in your app's source root.
  3. In your app/build.gradle, add the following stanza to dependencies: implementation files('libs/android.car.jar')
Barehanded answered 17/7, 2023 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.