Android Auto Dekstop 主机 ANR:GET_APP_VERSION

问题描述

我正在使用一个应用,想在 Android Auto 上试用它。我正在使用 DHU 来模拟仪表板,但由于 ANR(应用程序无响应)错误,我无法看到布局。

enter image description here

我确实在 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 个选项:

  1. 更改库:
    将库从 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
  2. 使用新手机 --> Android 10 应该没问题。
    我的主要 Android 手机(xiaomi mi note 10 lite - Android 10)和 AndroidX 运行没有问题

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...