All Projects → mitchtabian → Dagger Hilt Playerground

mitchtabian / Dagger Hilt Playerground

A playground for learning dagger hilt on android

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Dagger Hilt Playerground

paybill-manager
Your personal finance manager
Stars: ✭ 46 (-69.54%)
Mutual labels:  dagger2, dagger2-android
Instant Weather
An Android weather application implemented using the MVVM pattern, Retrofit2, Dagger2, LiveData, ViewModel, Coroutines, Room, Navigation Components, Data Binding and some other libraries from the Android Jetpack.
Stars: ✭ 473 (+213.25%)
Mutual labels:  dagger2, dagger2-android
Mvp Dagger2 Rxjava2
Android 基本mvp+dagger(dagger2.android)+rxjava2+retrofit+ormdb框架。简单组件化架构 with Base Activity,Presenter ,View,Model 的抽象封装,http 请求封装&错误统一处理
Stars: ✭ 274 (+81.46%)
Mutual labels:  dagger2, dagger2-android
WanAndroid
一个简洁漂亮与众不同的WanAndroid客户端,欢迎下载体验(〃'▽'〃)。(A simple and beautiful Wanandroid client App.) MVVM + Dagger2 + DataBinding + Lifecycle + OkHttp + Retrofit2
Stars: ✭ 81 (-46.36%)
Mutual labels:  dagger2, dagger2-android
Simple Example Dagger Android
Example repository displaying the usage of Dagger's new Android injection
Stars: ✭ 13 (-91.39%)
Mutual labels:  dagger2, dagger2-android
mvp-android-template
MVP Android Template to give you a Quick Head Start for your next Android Project. It implements MVP Architecture using Dagger2, Room, RxJava2 , Retrofit2
Stars: ✭ 20 (-86.75%)
Mutual labels:  dagger2, dagger2-android
Mvvmarms
Android MVVM Architecture Components based on MVPArms and Android Architecture Components.
Stars: ✭ 425 (+181.46%)
Mutual labels:  dagger2, dagger2-android
CleanArchitecture-SocketIO
CleanArchitecture with SocketIo 📡
Stars: ✭ 32 (-78.81%)
Mutual labels:  dagger2, dagger2-android
Roomrxjava
Room with Rxjava Example
Stars: ✭ 130 (-13.91%)
Mutual labels:  dagger2, dagger2-android
Anvil
A Kotlin compiler plugin to make dependency injection with Dagger 2 easier.
Stars: ✭ 615 (+307.28%)
Mutual labels:  dagger2, dagger2-android
Kotlin Mvvm Architecture
Android Architecture Design Patterns using Kotlin, MVVM, Dagger2, LiveData, Room, MediatorLiveData, NetworkBoundResources, Retrofit, AndroidX, ViewModels, Dependency Injection using Dagger2, Repository pattern.
Stars: ✭ 126 (-16.56%)
Mutual labels:  dagger2, dagger2-android
Frekans
📻 Frekans is a radio player app. It will be fully developed with Kotlin. It is work-in-progress and under heavy development.
Stars: ✭ 43 (-71.52%)
Mutual labels:  dagger2, dagger2-android
flickr-android
A small sample app to showcase architecting app using Clean Architecture and MVVM
Stars: ✭ 25 (-83.44%)
Mutual labels:  dagger2, dagger2-android
AndroidMVPArchitecture
Android MVP architecture sample project with or without RxJava and Dagger2 and Kotlin
Stars: ✭ 78 (-48.34%)
Mutual labels:  dagger2, dagger2-android
AndroidCleanArchitecture
Android Project with clean android architecture contain Dagger, Retrofit, Retrofit, Android archtecture components, LiveData with MVVM architecture
Stars: ✭ 22 (-85.43%)
Mutual labels:  dagger2, dagger2-android
Learndagger
List of resources to learn about Dependency Injection and Dagger 2
Stars: ✭ 381 (+152.32%)
Mutual labels:  dagger2, dagger2-android
Praxis
Example Android project using MVVM, DaggerAndroid, Jetpack Compose, Retrofit, Coroutines and Multi module architecture ✌🏽
Stars: ✭ 258 (+70.86%)
Mutual labels:  dagger2, dagger2-android
Klean-ArchiteKture
Kotlin Android clean-architecture demo project for a meetup talk. Slides: https://docs.google.com/presentation/d/1CxnntHf3CorNDicx_cDN5s1t5pEbUwjwWHZ5PNmfe6Y/edit?usp=sharing
Stars: ✭ 10 (-93.38%)
Mutual labels:  dagger2, dagger2-android
Theatre
Pet project using Clean Architecture + MVVM + Reactive Extensions + Android Architecture Components. The data are fetched from LondonTheatreDirect API. 🎭
Stars: ✭ 577 (+282.12%)
Mutual labels:  dagger2, dagger2-android
Mvp With Dagger 2.11
Stars: ✭ 20 (-86.75%)
Mutual labels:  dagger2, dagger2-android

Dagger Hilt

Playground for learning how to use Hilt. A new way to incorporate Dagger dependency injection into an Android application.

Examples

Below is a list of examples.

Hilt Basics

I will be making video lectures using the gists below as examples.

  1. Preparing to use Hilt
  2. Field injecting a class with no dependencies. You own that class.
  3. Scopes and the "tier-like" system
  4. Dependencies that require dependencies (Concrete classes that you own)
  5. Some things can't be constructor-injected. What is the solution?
  6. Hilt Modules, Binds and Provides
  7. Multiple Bindings of the same type

Basic MVI Repository Pattern

NOTE This is not how I would build out the architecture normally. I greatly simplified this for beginners. See Simple Network & Cache Use-case for a Clean Architecture Implementation of the same thing.

  1. Retrieve data from open-api.xyz with Retrofit
  2. Cache data with Room
  3. Display cached data in UI

Simple Network & Cache Use-case

  1. Retrieve data from open-api.xyz with Retrofit
  2. Cache data with Room
  3. Display cached data in UI

Fragment Constructor Injection with Hilt

  1. How to do fragment constructor injection with Hilt.

Instrumentation Testing

Guide:

https://developer.android.com/training/dependency-injection/hilt-testing

Important points:

  1. Dependencies
    1. Hilt
      • androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
      • kaptAndroidTest "com.google.dagger:hilt-android-compiler:$hilt_version"
    2. launchFragmentInContainer
      • debugImplementation "androidx.fragment:fragment-testing:$fragment_version"
  2. Test classes
    • Annotate with @HiltAndroidTest. Example
    • Include HiltAndroidRule. Example
  3. HiltTestApplication
    • Hilt automatically generates a HiltTestAppliaction. But it requires a custom Test Runner (see next point)
  4. Custom Test Runner
  5. Field Injection
    • Requres hiltRule.inject() in @Before function of test class. Example
  6. Test Fakes
    1. Method 1: Replacing a Module
      1. Uninstall the module in the test class
        • @UninstallModules(AnalyticsModule::class). Example
      2. Create a new module within the test class that replaces the old module. Example
    2. Method 2: @BindValue
  7. Custom Application for testing
    • Guide
    • I guess you might have to do this if one of your dependencies requires your custom Application class. But I think you could probably work-around this.
  8. Multiple Test rules
    • Guide
    • I didn't know this was an issue? Never encountered this.
  9. launchFragmentInContainer
    • launchFragmentInContainer does not work with Hilt because the activity it creates is not annotated with @AndroidEntryPoint. So there is a work-around:
    • Guide
    • launchFragmentInHiltContainer work-around:
      1. Create HiltExt.kt
        • NOTE One short-coming of this work-around is you cannot specify a FragmentFactory to the function. I made a slight modification so you can. That way you can do constructor injection. Modified HiltExt.kt
      2. Create /debug/HiltTestActivity.kt
      3. Create /debug/AndroidManifest.xml
      4. Launch the fragment: val scenario = launchFragmentInHiltContainer<MainFragment>( factory = fragmentFactory )

Issues

I got this weird error:

Could not determine the dependencies of task ':app:processDebugAndroidTestManifest'.
> Could not resolve all task dependencies for configuration ':app:debugAndroidTestRuntimeClasspath'.
   > Could not resolve com.google.code.findbugs:jsr305:{strictly 3.0.1}.
     Required by:
         project :app
      > Cannot find a version of 'com.google.code.findbugs:jsr305' that satisfies the version constraints: 
           Dependency path 'DaggerHiltPlayground:app:unspecified' --> 'androidx.test.espresso:espresso-core:3.2.0' --> 'com.google.code.findbugs:jsr305:2.0.1'
           Constraint path 'DaggerHiltPlayground:app:unspecified' --> 'com.google.code.findbugs:jsr305:{strictly 3.0.1}' because of the following reason: debugRuntimeClasspath uses version 3.0.1
           Dependency path 'DaggerHiltPlayground:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.28-alpha' --> 'com.google.code.findbugs:jsr305:3.0.1'
           Dependency path 'DaggerHiltPlayground:app:unspecified' --> 'com.google.dagger:hilt-android:2.28-alpha' --> 'com.google.code.findbugs:jsr305:3.0.1'
           Dependency path 'DaggerHiltPlayground:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.28-alpha' --> 'com.google.guava:guava:27.1-jre' --> 'com.google.code.findbugs:jsr305:3.0.2'

Solution

https://github.com/invertase/react-native-firebase/issues/1954

I just added this to build.gradle and everything worked fine:

android {
    ... 

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0'
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].