You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to Use @AndroidEntryPoint with androidx.car.app Android Auto Screen #4758
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?
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
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.
Activity
dmapr commentedon Jun 12, 2025
I think https://dagger.dev/hilt/entry-points.html will point you in the right direction. You can treat
Screenthe same as theNonHiltLibraryClassin the example.Chang-Eric commentedon Jun 17, 2025
We don't really have a recommendation for
Screenor 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
ScreenComponentfollowing https://dagger.dev/hilt/custom-components. Otherwise just using entry points would only allow you access to things inSingletonComponentmiltonjmc commentedon Sep 19, 2025
The only place to use the
@AndroidEntryPointin a car app is theCarAppServiceYou can inject the object needed in
CarAppServiceand just pass it on to the session and screens.