MediaBrowserServiceCompat
へ @AndroidEntryPoint
を使って依存関係を注入しようとすると、以下のエラーがでてしまいます。
エラー: MediaBrowserServiceCompatにアクセスできません
androidx.media.MediaBrowserServiceCompatのクラス・ファイルが見つかりません
これを解決するために、新たに EntryPoint
を定義します。
@EntryPoint
@InstallIn(ApplicationComponent::class)
internal interface MediaBrowserServiceCompatInterface {
fun getHoge(): Hoge
}
そして、 MediaBrowserServiceCompat
内でこれを使って注入します。
EntryPoints.get(applicationContext, MediaBrowserServiceCompatInterface::class.java).also {
this.hoge = it.getHoge()
}
Entry Points - Hilt のBestPracticeにはクラス内にInterfaceを定義し、それを使うことが推奨されていますが、 MediaBrowserServiceCompat
の場合はうまく動きません。おとなしく別ファイルに書くしかないようです。
MediaBrowserServiceCompatはServiceを継承しているので、AndroidEntryPointでかけそうなものですがなにがだめなのでしょうか。。。もし、なにかいい方法をご存じの方がおられたら、コメントで教えていただけると嬉しいです!