2

Unable to access to android.car package.

After adding useLibrary 'android.car' to build.gradle of app module it started building and running on emulator, but Android Studio still unable to access and/or show them.

import android.car.Car
import android.car.VehiclePropertyIds
import android.car.hardware.CarPropertyValue
import android.car.hardware.property.CarPropertyManager

Android Studio versions:

  1. Chipmunk 2021.2.1 | Patch 1
  2. Electric Eel | 2022.1.1 Canary 2

Android SDK: 29, 30, 31, 32

How can I fix it. Or somehow add android.car.jars. Because it is impossible to normally develop without highlighting and importing packages.

Sever
  • 2,338
  • 5
  • 35
  • 55
  • For now, I just add from sdk/platforms/android-32/optional/android.car.jar to app/libs folder of the project. 32 is my compileSdkVersion and targetSdkVersion version. And seems it is correctly show now. But I really dont like that solution. – Sever Jun 06 '22 at 12:23

4 Answers4

6

The issue is still there in Google Issue Tracker

OPTION 1:

1- Copy sdkDir/platforms/android-XX/optional/android.car.jar to yourProjectDir/app/libs/android.car.jar

I tested with android-32

2- Add it to the dependencies section in your build.gradle

compileOnly files("libs/android.car.jar")

OPTION 2:

Based on @werner's answer for groovy build.gradle

    def sdkDir = project.android.sdkDirectory.canonicalPath
    def androidCarJar = "$sdkDir/platforms/android-32/optional/android.car.jar"
    implementation(files(androidCarJar))

Tested on:

Android Studio Chipmunk | 2021.2.1 Patch 1

Android Studio Electric Eel | 2022.1.1 Canary 8

Morteza Rastgoo
  • 6,772
  • 7
  • 40
  • 61
  • 1
    Test on Flamingo as well, and according to issue tracker it should be fixed in next Android Studio version. – HucKQC Jun 07 '23 at 12:38
4

In my project I have a similar problem, when I have upgraded target sdk version from 32 to 33. It occurs when pro-guard is enabled. I have tried many solutions. But the solution which worked for me is,

To move android.car.jar package path from /Users/$username/Library/Android/sdk/platforms/android-33/optional to /Users/$username/Library/Android/sdk/platforms/android-33.

Hope it will helps you too.

2

Not a real answer to the question (can't comment yet):

in our project we have a similar problem. Chipmunk does not detect and/or resolve our project's custom SDK add-on. It worked with BumbleBee.

We added dependencies to include the JAR files of the custom add-on, like this:

// See comment in the dependencies section below
val sdkDir: String = project.android.sdkDirectory.canonicalPath
val addOnPath = "$sdkDir/add-ons/addon-project-add-on/libs"

...
    // FIXME: Currently AS Chipmunk seems to have an issue to resolve custom SDK add-on
    //        jars. Gradle works and builds, only the IDE part seems to have a problem.
    //        The next line explicitly adds the custom SDK add-on JAR files as dependencies
    //        and AS Chipmunk's IDE part can now resolve classes etc.
    //        This is a workaround and maybe even a dirty trick and should be removed once
    //        AS was fixed. Need to check if this also works with CI (zuul)
    implementation(fileTree(mapOf("dir" to addOnPath, "include" to listOf("*.jar"))))

In this regard Chipmunk is broken IMHO.

We also use Android-car and use this:

val androidCarJar = "$sdkDir/platforms/android-30/optional/android.car.jar"

...
implementation(files(androidCarJar))

We do not copy the JAR, just reference it directly.

0

Adding Car APIs (android.car.Car) support in Android Studio

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

SAURABH_12
  • 2,262
  • 1
  • 19
  • 19