android.car package is unavailable in Android Studio

Viewed 647

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.

2 Answers

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.

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

Related