英文:
Can't use Android Auto 'android.car' library - throws RuntimeException: Stub
问题
I'm here to provide a translation of the text you provided. Here's the translated text:
我正在尝试从运行Android Auto和Android Automotive的汽车中读取外部温度传感器。
为了使用CarPropertyManager读取SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE,我需要包含android.car库。然而,在Android Auto(桌面Head Unit)上运行时,它一直抛出runtimeexception。
java.lang.runtimeexception: stub! at android.car.car.createcar
我尝试将useLibrary 'android.car'
添加到gradle文件中(如此处描述的):
android {
compileSdkVersion 33
...
useLibrary 'android.car'
}
然而,在Android Auto(桌面Head Unit)上运行时,我收到以下错误:
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/car/hardware/property/CarPropertyManager$CarPropertyEventCallback;
为了修复NoClassDefFoundError,我按照SDK文件夹中的方式导入了库(如此处描述的):
val sdkDir: String = project.android.sdkDirectory.canonicalPath
val androidCarJar = "$sdkDir/platforms/android-33/optional/android.car.jar"
dependencies {
implementation(files(androidCarJar))
}
然而,当我尝试运行应用程序时,我收到以下错误:
java.lang.runtimeexception: stub! at android.car.car.createcar
在搜索错误后,我找到了以下解释在StackOverflow上 / 和这里
android.jar仅包含类的存根实现。它提供了构建应用程序的手段,一旦生成了APK,您必须在Android设备或模拟器上运行它。
这是有道理的,但我尝试在模拟器上以及在汽车内运行它,但仍然遇到问题。
然后,我查看了Android Auto的官方示例,注意到它们只在Android Automotive项目中访问Car API,而不在Android Auto项目中访问,所以我想知道这是否只是Android Automotive的特性。我找不到任何相关的文档。
根据Car的文档,第一句明确说明了“Android Auto”。
用于嵌入式Android Auto部署的顶级汽车API。此API仅适用于具有PackageManager#FEATURE_AUTOMOTIVE的设备
然而,如果我在桌面Head Unit中检查该功能,它告诉我不支持它。
我使用Car API的方式如下(与官方示例应用程序相同):
car = Car.createCar(carContext)
我漏掉了什么?
英文:
I'm trying to read the Outside Temperature Sensor from cars running Android Auto and Android Automotive.
In order to read the SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE using the CarPropertyManager I need to include the android.car
library. However when running it on Android Auto (Desktop Head Unit) it keeps on throwing a runtimeexception
.
`java.lang.runtimeexception: stub! at android.car.car.createcar`
I tried adding the useLibrary 'android.car'
to the gradle file (as described here)
android {
compileSdkVersion 33
...
useLibrary 'android.car'
}
However when running it on Android Auto (Desktop Head Unit) I get the following error:
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/car/hardware/property/CarPropertyManager$CarPropertyEventCallback;
To fix the NoClassDefFoundError
I imported the lib from the SDK folder as follows (as described here):
val sdkDir: String = project.android.sdkDirectory.canonicalPath
val androidCarJar = "$sdkDir/platforms/android-33/optional/android.car.jar"
dependencies {
implementation(files(androidCarJar))
}
However when I try to run the app I get the follow error:
java.lang.runtimeexception: stub! at android.car.car.createcar
After searching for the error I found the following explanation on StackOverflow / and here
> android.jar contains only stub implementation of the classes. It provides the means for you app to build, once you have your APK you must run it on an android device or emulator.
Which makes sense however I tried running it both on an Emulator as well as inside a car.
Then I looked through the official samples for Android Auto and noticed that they only accessed the Car
API in the Android Automotive project but not in the Android Auto project so I'm wondering if this is an Android Automotive Feature only.. I can't find any documentation on that..
According to the docs for the Car
, the first sentence clearly says "Android Auto".
> Top level car API for embedded Android Auto deployments. This API works only for devices with PackageManager#FEATURE_AUTOMOTIVE
However if I check for that Feature in the Desktop Head Unit it tells me that it's not supported.
I'm using the Car API like this (same as in the official sample app):
car = Car.createCar(carContext)
What am I missing?
答案1
得分: 2
android.car
库仅适用于Android Automotive OS。这可能不太明显,但你引用的注释确认了这一点 - “嵌入式Android Auto”就是指Android Automotive OS。该文档注释只是在官方为Automotive OS确定名称之前编写的。
目前在Android Auto上无法读取外部温度。有关可以在Android Auto上读取的硬件的详细信息,请参阅Car Hardware APIs。
英文:
The android.car
library is only for Android Automotive OS. It's a bit non-obvious, but the comment you referenced does confirm this - "embedded Android Auto" is Android Automotive OS. That doc comment was just written before there was an official name for Automotive OS.
There currently isn't a way to read outside temperature on Android Auto. See Car Hardware APIs for details on which hardware can be read from on Android Auto.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论