-
-
Save nuhkoca/1bf28190dc71b00a2f32ce425f99924d to your computer and use it in GitHub Desktop.
BindingScoped.kt | |
@Scope | |
@Retention(AnnotationRetention.BINARY) | |
annotation class BindingScoped | |
------------------------------------------------------- | |
CustomBindingComponent.kt | |
@BindingScoped | |
@DefineComponent(parent = SingletonComponent::class) | |
interface CustomBindingComponent | |
------------------------------------------------------- | |
CustomBindingComponentBuilder.kt | |
@DefineComponent.Builder | |
interface CustomBindingComponentBuilder { | |
fun build(): CustomBindingComponent | |
} | |
------------------------------------------------------- | |
CustomBindingEntryPoint.kt | |
@EntryPoint | |
@BindingScoped | |
@InstallIn(CustomBindingComponent::class) | |
interface CustomBindingEntryPoint: DataBindingComponent { | |
@BindingScoped | |
override fun getImageBindingAdapter(): ImageBindingAdapter | |
} | |
------------------------------------------------------- | |
MyApp.kt | |
@HiltAndroidApp | |
class MyApp : Application() { | |
@Inject | |
lateinit var bindingComponentProvider: Provider<CustomBindingComponentBuilder> | |
override fun onCreate() { | |
super.onCreate() | |
val dataBindingComponent = bindingComponentProvider.get().build() | |
val dataBindingEntryPoint = EntryPoints.get( | |
dataBindingComponent, CustomBindingEntryPoint::class.java | |
) | |
DataBindingUtil.setDefaultComponent(dataBindingEntryPoint) | |
} | |
} |
same issue,
symbol: class CustomBindingComponentBuilder
location: class App/home/yusuf/AndroidStudioProjects/MiK/app/src/main/java/me/modernpage/di/CustomBindingComponent.java:10: error: cannot find symbol
interface CustomBindingComponent extends DataBindingComponent {
^
symbol: class DataBindingComponent/home/yusuf/AndroidStudioProjects/MiK/app/src/main/java/me/modernpage/di/CustomBindingComponent.java:10: error: [Hilt]
interface CustomBindingComponent extends DataBindingComponent {
^
@DefineComponent me.modernpage.di.CustomBindingComponent, cannot extend a super class or interface. Found: DataBindingComponent
@ModerPage it is working well for me. The only difference is that ApplicationComponent
was replaced with SingletonComponent
. Otherwise rest of the code remains the same. Please check and let me know if it works for you, too!
For those who are being stuck on this gist to fix issues running around Hilt and DataBinding implementation, I created a working sample repository for you! Please take a look at it if you want to see how it is working.
Repository: https://github.com/nuhkoca/HiltDataBindingSample
Thanks alot. its working now @nuhkoca
That's great to hear! @AhmMhd
Hi Abdul,
Thanks for your interest. Do you enable
DataBinding
in your project or use a newer version of Hilt? As far as I remember, they were planning to ease usage of Hilt for transitive functions. Can you please try it with lower versions or take a look at issues? Or you can share the project with me to check it out if possible. Please let me know. Thanks.