7

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?

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73

5 Answers5

14

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

Farid
  • 1,024
  • 9
  • 16
Selim Gurun
  • 174
  • 1
  • 2
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.

fejd
  • 2,545
  • 1
  • 16
  • 39
  • Also found this in Google's issue tracker for some supporting info: https://issuetracker.google.com/issues/74386715 – salminnella Mar 12 '19 at 22:30
  • 1
    `make android.car`does not work. how can I create android.car.jar from Android.bp? – Ugurcan Yildirim Mar 13 '19 at 07:43
  • 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//system/framework/android.car.jar. – fejd Mar 13 '19 at 08:10
  • I'm getting the following error when I run `mm` or `mma` command: `Couldn't locate the top of the tree. Try setting TOP.` – Ugurcan Yildirim Mar 13 '19 at 11:10
  • TOP or ANDROID_BUILD_TOP should be the root of the AOSP tree. I thought "source build/envsetup" would set that up though. – fejd Mar 13 '19 at 11:57
0

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

. build/envsetup.sh

lunch aosp_car_x86-userdebug

make -j8
sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Rohit
  • 1
  • 2
0

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

GS Nayma
  • 1,745
  • 19
  • 24
0

For those where https://stackoverflow.com/a/63321234/361413 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')
bk138
  • 3,033
  • 1
  • 34
  • 28