无法访问android.car包。
添加useLibrary 'android.car'
后。gradle的应用模块,它开始构建和运行在模拟器上,但Android Studio仍然无法访问和/或显示它们。
import android.car.Car
import android.car.VehiclePropertyIds
import android.car.hardware.CarPropertyValue
import android.car.hardware.property.CarPropertyManager
Android Studio版本:
- 花栗鼠2021.2.1 |补丁1
- 电鳗| 2022.1.1金丝雀2
Android SDK: 29,30,31,32
我该如何修复它?或者添加android.car.jar。因为不突出显示和导入包是不可能正常开发的。
这个问题仍然存在于Google issue Tracker
选项1:
1-复制sdkDir/platforms/android-XX/optional/android.car.jar
到yourProjectDir/app/libs/android.car.jar
我用android-32
测试
2-将其添加到build.gradle
compileOnly files("libs/android.car.jar")
选项2:
基于@werner对groovybuild.gradle
的回答
def sdkDir = project.android.sdkDirectory.canonicalPath
def androidCarJar = "$sdkDir/platforms/android-32/optional/android.car.jar"
implementation(files(androidCarJar))
测试:
Android Studio Chipmunk | 2021.2.1 Patch 1
Android Studio Electric Eel | 2022.1.1 Canary 8
在我的项目中,当我将目标sdk版本从32升级到33时,我有类似的问题。当启用pro-guard时发生。我已经尝试了很多解决方案。但对我有效的解决方案是,
android.car.jar从/Users/$username/Library/Android/sdk/platforms/android-33/optional
到/Users/$username/Library/Android/sdk/platforms/android-33
的包路径
希望对你也有帮助。
不是问题的真正答案(还不能评论):
在我们的项目中,我们有一个类似的问题。花栗鼠不检测和/或解决我们项目的自定义SDK附加组件。它对大黄蜂起作用了。我们添加依赖项以包含自定义附加组件的JAR文件,如下所示:
// 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"))))
在这方面,花栗鼠是坏的。
我们也使用Android-car并使用这个:
val androidCarJar = "$sdkDir/platforms/android-30/optional/android.car.jar"
...
implementation(files(androidCarJar))
我们不复制JAR,直接引用它。
在Android Studio中添加Car api (Android .Car .Car)支持
Note: You need to have AOSP code to achieve this solution
步骤1。转到您的AOSP代码库并运行下面提到的命令
AOSP$ source build/envsetup.sh
AOSP$ lunch aosp_car_x86-userdebug
AOSP$ cd packages/services/Car/car-lib
AOSP$ mm
car-lib模块成功构建后,转到下面提到的路径并复制classes.jar文件
AOSP$ cd out/target/common/obj/JAVA_LIBRARIES/android.car_intermediates/
复制classes.jar文件并粘贴到项目的libs文件夹中(例如MyApp/app/libs)
右键单击libraries中的classes.jar文件并选择Add as Library选项
或
你可以直接在你的构建依赖中添加实现文件('libs/classes.jar')。Gradle (app)文件