skip to Main Content

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.

3

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search