Skip to content

Unable to Use @AndroidEntryPoint with androidx.car.app Android Auto Screen #4758

Open

Description

@vishwadg

Configuration:

Hilt version: 2.51.1
Car App Library version: androidx.car.app:app:1.4.0

Issue Summary:
I'm encountering an issue when trying to use Hilt's @AndroidEntryPoint annotation within a class that extends androidx.car.app.Screen in an Android Auto app.

Context:
In my Android Auto application, I attempted to annotate a Screen class with @AndroidEntryPoint to enable dependency injection. However, this results in the following error:

[Hilt] @AndroidEntryPoint base class must extend ComponentActivity, (support) Fragment, View, Service, or BroadcastReceiver.

Since Screen is not a subclass of any of the supported Android components (e.g., Activity, Fragment, View, etc.), Hilt does not currently support injection in this context.

Feature Request / Question:
Is there a recommended way to use Hilt for dependency injection within Screen classes in Android Auto apps? If not, would it be possible to extend Hilt support to include Screen or provide guidance on best practices for DI in this scenario?

Activity

  1. dmapr commented on Jun 12, 2025

    @dmapr

    I think https://dagger.dev/hilt/entry-points.html will point you in the right direction. You can treat Screen the same as the NonHiltLibraryClass in the example.

  2. Chang-Eric commented on Jun 17, 2025

    @Chang-Eric
    Member

    We don't really have a recommendation for Screen or Android Auto. Perhaps in some future, but largely our team just is not familiar with Android Auto APIs at all and so probably something custom would be better than us trying to figure out the right standard Hilt components for that.

    In addition to the recommendation above to use entry points, you can create your own custom ScreenComponent following https://dagger.dev/hilt/custom-components. Otherwise just using entry points would only allow you access to things in SingletonComponent

  3. miltonjmc commented on Sep 19, 2025

    @miltonjmc

    The only place to use the @AndroidEntryPoint in a car app is the CarAppService
    You can inject the object needed in CarAppService and just pass it on to the session and screens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions