0

I'm sitting with an app and want to try it out for Android Auto. Im using the DHU for emulating the dashboard, but I'm not able to see the layout due to an ANR (Application not responding) error.

enter image description here

I do get one error in the logcat, but I'm unsure if its related to this:

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)

My code is basically this

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
        }
    }
}

and I've added the necessay tags to the manifest:

<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>
MikkelT
  • 633
  • 1
  • 10
  • 16

3 Answers3

0

I had the same Problem. Depending on how new your Android-phone is, you should have 2 options:

  1. Change Library:
    Changing the library from AndroidX to com.google.android Migration Guide, (just backwords) is a downgrade. AndroidX provides more functionality and will be updated regularly - com.google.android is closed. For a first impression should it be ok, for further approaches is AndroidX recommended
    Try HelloWorld demo to check it functionality
    --> In my case, the problem was a "old" pysicaly phone with Android 9 and the old library works without any problems but AndroidX not.
    Helpfully links:
    AndroidX Car App Library overview
    com.google.android Library overview
  2. Use a new Phone --> Android 10 should be OK.
    My main Android Phone (xiaomi mi note 10 lite - Android 10) and AndroidX works without problems
Myrmidon
  • 1
  • 1
  • 1
    To make your answer more relevant, you should explain what changing the library involves and what it should be changed to. It would also be helpful to explain why changing the Android version will make things better and what problems the use of the current library is causing. – Jason K. Mar 09 '21 at 01:49
  • I used a Pixel 3a with A11, so hardly something old :/ – MikkelT Mar 09 '21 at 20:26
0

I was using a Samsung 9 with Android 10 when I ran into this error, then switched to my Pixel 3XL with Android 11 and it started working. Really odd!

jQN
  • 459
  • 6
  • 5
0

Add in your app proguard-rules:

-keep class androidx.car.app.** { *; }
Javier
  • 291
  • 2
  • 10