LoginSignup
2
0

More than 1 year has passed since last update.

Dagger Hiltで @Singleton を使うときの @InstallIn は SingletonComponent

Last updated at Posted at 2021-01-17

一行で言うと

@Singleton@InstallInSingletonComponent じゃないと使えません。 1

事象

@InstallInActivityComponent の Module で @Singleton すると、以下のビルドエラーとなる。

error: [Dagger/IncompatiblyScopedBindings] com.example.XXXApplication_HiltComponents.ActivityC scoped with @dagger.hilt.android.scopes.ActivityScoped may not reference bindings with different scopes: public abstract static class SingletonC implements XXXApplication_GeneratedInjector

Hilt を使用した依存関係の注入  |  Android デベロッパー  |  Android Developers の例だと @InstallIn が ActivityComponent になっているので、注意しましょう。

その他

Dagger Hiltは2021年3月時点で、2.33-betaです。


  1. Dagger 2.31以前は ApplicationComponent でしたが、 2.32から SingletonComponent に変わりました。2.32以上にあげると error: cannot find symbol @dagger.hilt.InstallIn(value = {ApplicationComponent.class}) というエラーになります。 

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0