如何解决Android Auto Dekstop 主机 ANR:GET_APP_VERSION
我正在使用一个应用,想在 Android Auto 上试用它。我正在使用 DHU 来模拟仪表板,但由于 ANR(应用程序无响应)错误,我无法看到布局。
我确实在 logcat 中收到一个错误,但我不确定它是否与此有关:
2021-03-04 15:36:07.654 19595-19616/com.ooono.app W/Binder: Caught a RuntimeException from the binder stub implementation.
java.lang.SecurityException: Binder invocation to an incorrect interface
at android.os.Parcel.nativeEnforceInterface(Native Method)
at android.os.Parcel.enforceInterface(Parcel.java:650)
at androidx.car.app.ICarapp$Stub.onTransact(ICarapp.java:207)
at android.os.Binder.execTransactInternal(Binder.java:1159)
at android.os.Binder.execTransact(Binder.java:1123)
我的代码基本上是这样
import android.content.Intent
import android.content.pm.ApplicationInfo
import androidx.car.app.*
import androidx.car.app.model.*
import androidx.car.app.navigation.model.NavigationTemplate
import androidx.car.app.validation.HostValidator
class Caractivity : CarappService() {
override fun createHostValidator(): HostValidator {
return if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE !== 0) {
HostValidator.ALLOW_ALL_HOSTS_VALIDATOR
} else {
HostValidator.Builder(this)
.addAllowedHosts(R.array.hosts_allowlist_sample)
.build()
}
}
override fun onCreateSession(): Session {
return object : Session(){
override fun onCreateScreen(intent: Intent): Screen {
return NavScreen(carContext)
}
}
}
class NavScreen(carContext: CarContext) : Screen(carContext){
override fun onGetTemplate(): Template {
val listTemplate = ListTemplate.Builder().apply {
addSectionedList(SectionedItemList.create(
ItemList.Builder()
.addItem(Row.Builder().setTitle("list 1").addText("hellowrodl").build())
.build(),"List"
))
}
return listTemplate.build()
}
private fun actionStrip():ActionStrip{
val strip = ActionStrip.Builder().apply {
addAction(Action.Builder().setIcon(CarIcon.APP_ICON).setTitle("Ooono").setonClickListener { }.build())
}.build()
return strip
}
}
}
<Meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
<service
android:name=".aa.Caractivity"
android:label="@string/common_app_name"
android:icon="@mipmap/ic_launcher"
android:foregroundServiceType="location"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarappService"/>
<category android:name="androidx.car.app.category.NAVIGATION"/>
</intent-filter>
</service>
解决方法
我遇到了同样的问题。根据您的 Android 手机的新程度,您应该有 2 个选项:
- 更改库:
将库从 AndroidX 更改为 com.google.android Migration Guide,(just backwords) 是一种降级。 AndroidX 提供了更多功能并将定期更新 - com.google.android 已关闭。对于第一印象应该可以,对于进一步的方法建议使用 AndroidX
尝试HelloWorld demo来检查它的功能
--> 就我而言,问题是带有 Android 9 的“旧”pysicaly 手机,旧库可以正常工作,但 AndroidX 没有。
有用的链接:
AndroidX Car App Library overview
com.google.android Library overview - 使用新手机 --> Android 10 应该没问题。
我的主要 Android 手机(xiaomi mi note 10 lite - Android 10)和 AndroidX 运行没有问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。