title: Dagger-Hilt: @ViewModelInject is not injecting MyViewModel and crash?
body: <p>In exploring the ViewModelInject of Dagger-Hilt, I follow the example in <a href="https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodels" rel="noreferrer">https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodels</a></p>
  <p>I try to inject the ViewModel into my activity as follow</p>
  <pre><code>import android.app.Application
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import androidx.activity.viewModels
  import androidx.hilt.Assisted
  import androidx.hilt.lifecycle.ViewModelInject
  import androidx.lifecycle.*
  import androidx.savedstate.SavedStateRegistryOwner
  import dagger.hilt.android.AndroidEntryPoint
  import dagger.hilt.android.HiltAndroidApp
  import kotlinx.android.synthetic.main.activity_main.*
  import javax.inject.Inject
  import javax.inject.Singleton
  
  @HiltAndroidApp
  class MainApplication: Application()
  
  @AndroidEntryPoint
  class MainActivity : AppCompatActivity() {
  
      private val viewModel: MyViewModel by viewModels()
  
      private val textDataObserver =
          Observer&lt;String&gt; { data -&gt; text_view.text = data }
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          viewModel.showTextDataNotifier.observe(this, textDataObserver)
          btn_fetch.setOnClickListener { viewModel.fetchValue() }
      }
  }
  
  class MyViewModel @ViewModelInject constructor(
      @Assisted val savedStateHandle: SavedStateHandle,
      val repository: Repository
  ) :
      ViewModel(), LifecycleObserver {
  
      private val showTextLiveData
              = savedStateHandle.getLiveData&lt;String&gt;(&quot;DefaultKey&quot;)
  
      val showTextDataNotifier: LiveData&lt;String&gt;
          get() = showTextLiveData
  
      fun fetchValue() {
          showTextLiveData.value = repository.getMessage()
      }
  }
  
  
  @Singleton
  class Repository @Inject constructor() {
      fun getMessage() = &quot;From Repository&quot;
  }
  
  </code></pre>
  <p>It crash complaining</p>
  <pre><code>     Caused by: java.lang.RuntimeException: Cannot create an instance of class com.elyeproj.simplehilt.MyViewModel
          at androidx.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:221)
          at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:278)
          at androidx.lifecycle.SavedStateViewModelFactory.create(SavedStateViewModelFactory.java:106)
          at androidx.hilt.lifecycle.HiltViewModelFactory.create(HiltViewModelFactory.java:69)
  </code></pre>
  <p>I try manually creating the ViewModel using the view model factory (the non-injection approach), it works fine.</p>
  <pre><code>import android.app.Application
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import androidx.activity.viewModels
  import androidx.hilt.Assisted
  import androidx.hilt.lifecycle.ViewModelInject
  import androidx.lifecycle.*
  import androidx.savedstate.SavedStateRegistryOwner
  import dagger.hilt.android.AndroidEntryPoint
  import dagger.hilt.android.HiltAndroidApp
  import kotlinx.android.synthetic.main.activity_main.*
  import javax.inject.Inject
  import javax.inject.Singleton
  
  @HiltAndroidApp
  class MainApplication: Application()
  
  @AndroidEntryPoint
  class MainActivity : AppCompatActivity() {
  
      private val viewModel: MyViewModel by viewModels{
          MyViewModelFactory(this, Repository(), intent.extras)
      }
  
      private val textDataObserver =
          Observer&lt;String&gt; { data -&gt; text_view.text = data }
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          viewModel.showTextDataNotifier.observe(this, textDataObserver)
          btn_fetch.setOnClickListener { viewModel.fetchValue() }
      }
  }
  
  class MyViewModelFactory(
      owner: SavedStateRegistryOwner,
      private val repository: Repository,
      defaultArgs: Bundle? = null
  ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
      override fun &lt;T : ViewModel&gt; create(key: String, modelClass: Class&lt;T&gt;, handle: SavedStateHandle
      ): T {
          return MyViewModel(
              handle,
              repository
          ) as T
      }
  }
  
  class MyViewModel @ViewModelInject constructor(
      @Assisted val savedStateHandle: SavedStateHandle,
      val repository: Repository
  ) :
      ViewModel(), LifecycleObserver {
  
      private val showTextLiveData
              = savedStateHandle.getLiveData&lt;String&gt;(&quot;DefaultKey&quot;)
  
      val showTextDataNotifier: LiveData&lt;String&gt;
          get() = showTextLiveData
  
      fun fetchValue() {
          showTextLiveData.value = repository.getMessage()
      }
  }
  
  @Singleton
  class Repository @Inject constructor() {
      fun getMessage() = &quot;From Repository&quot;
  }
  </code></pre>
  <p>Did I do anything wrong in the use of <code>@ViewModelInject</code>?</p>