title: How to inject `rememberNavController` from jetpack compose into an activity using hilt?
body: <p>I'm trying to inject my <code>navHostController</code> into my <code>MainActivity</code> using hilt. But I'm getting the following error when trying to compile the code:</p>
  <pre><code>&gt; Task :app:kaptDebugKotlin
  C:\Users\pierr\AndroidStudioProjects\AndroidApps\Compose\Udemy\course01\crud\app\build\generated\source\kapt\debug\com\example\crud\CrudApplication_HiltComponents.java:129: error: [Dagger/MissingBinding] androidx.navigation.NavHostController cannot be provided without an @Inject constructor or an @Provides-annotated method.
    public abstract static class SingletonC implements CrudApplication_GeneratedInjector,
                           ^
        androidx.navigation.NavHostController is injected at
            com.example.crud.ui.MainActivity.navHostController
        com.example.crud.ui.MainActivity is injected at
            com.example.crud.ui.MainActivity_GeneratedInjector.injectMainActivity(com.example.crud.ui.MainActivity) [com.example.crud.CrudApplication_HiltComponents.SingletonC ? com.example.crud.CrudApplication_HiltComponents.ActivityRetainedC ? com.example.crud.CrudApplication_HiltComponents.ActivityC]
  
  &gt; Task :app:kaptDebugKotlin FAILED
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':app:kaptDebugKotlin'.
  &gt; A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
     &gt; java.lang.reflect.InvocationTargetException (no error message)
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  
  * Get more help at https://help.gradle.org
  
  Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
  Use '--warning-mode all' to show the individual deprecation warnings.
  See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings
  
  BUILD FAILED in 5s
  24 actionable tasks: 2 executed, 22 up-to-date
  
  </code></pre>
  <p>This is my <code>MainActivity</code> code:</p>
  <pre class="lang-kotlin prettyprint-override"><code>package com.example.crud.ui
  
  import android.os.Bundle
  import androidx.activity.ComponentActivity
  import androidx.activity.compose.setContent
  import androidx.compose.material.MaterialTheme
  import androidx.compose.material.Surface
  import androidx.navigation.NavHostController
  import com.example.crud.navigation.NavigationComponent
  import com.example.crud.ui.theme.CRUDTheme
  import dagger.hilt.android.AndroidEntryPoint
  import javax.inject.Inject
  
  @AndroidEntryPoint
  class MainActivity : ComponentActivity() {
  
      @Inject lateinit var navHostController: NavHostController
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
  
          setContent {
              CRUDTheme {
                  Surface(color = MaterialTheme.colors.background) {
                      NavigationComponent(navHostController)
                  }
              }
          }
      }
  }
  </code></pre>
  <p>This is my <code>NavigationModule</code> code:</p>
  <pre class="lang-kotlin prettyprint-override"><code>package com.example.crud.di
  
  import androidx.compose.runtime.Composable
  import androidx.navigation.compose.rememberNavController
  import dagger.Module
  import dagger.hilt.InstallIn
  import dagger.hilt.android.components.ActivityComponent
  
  @Module
  @InstallIn(ActivityComponent::class)
  object NavigationModule {
      @Composable
      fun provideNavHostController() = rememberNavController()
  }
  </code></pre>
  <p>This is the code for the <code>NavigationComponent</code> (it takes as a parameter the <code>navHostController</code> I'm trying to inject into <code>MainActivity</code>):</p>
  <pre class="lang-kotlin prettyprint-override"><code>package com.example.crud.navigation
  
  import androidx.compose.runtime.Composable
  import androidx.compose.runtime.livedata.observeAsState
  import androidx.hilt.navigation.compose.hiltViewModel
  import androidx.navigation.NavHostController
  import androidx.navigation.NavType
  import androidx.navigation.compose.NavHost
  import androidx.navigation.compose.composable
  import androidx.navigation.navArgument
  import com.example.crud.ui.screens.crud.details.DetailScreen
  import com.example.crud.ui.screens.crud.register.RegisterScreen
  import com.example.crud.ui.screens.home.HomeScreen
  import com.example.crud.ui.screens.home.HomeViewModel
  
  @Composable
  fun NavigationComponent(navController: NavHostController) {
      NavHost(navController = navController, startDestination = Routes.HOME) {
          composable(Routes.HOME) {
              val homeViewModel: HomeViewModel = hiltViewModel()
              val cities = homeViewModel.cities.observeAsState(listOf())
              HomeScreen(
                  cities = cities,
                  navigateToDetailsAction = { navController.navigate(Routes.REGISTER) }
              ) { cityId -&gt;
                  navController.navigate(Routes.getDetailsDynamicRoute(cityId))
              }
          }
          composable(Routes.REGISTER) { RegisterScreen { navController.popBackStack() } }
          composable(
              route = Routes.DETAILS,
              arguments = listOf(navArgument(Routes.CITY_ID_KEY) { type = NavType.IntType })
          ) { backStackEntry -&gt;
              val cityId = backStackEntry.arguments?.getInt(Routes.CITY_ID_KEY)
              cityId?.let {
                  DetailScreen(cityId = it, popNavigation = { navController.popBackStack() })
              }
          }
      }
  }
  </code></pre>
  <p>I believe this is irrelevant to solving the problem, but the code in the <code>Routes.kt</code> file follows:</p>
  <pre class="lang-kotlin prettyprint-override"><code>package com.example.crud.navigation
  
  object Routes {
      private const val DETAILS_BASE_ROUTE = &quot;details/&quot;
      const val HOME = &quot;home&quot;
      const val REGISTER = &quot;register&quot;
      const val CITY_ID_KEY = &quot;cityId&quot;
      const val DETAILS = &quot;$DETAILS_BASE_ROUTE{$CITY_ID_KEY}&quot;
  
      fun getDetailsDynamicRoute(cityId: Int) = &quot;$DETAILS_BASE_ROUTE${cityId}&quot;
  }
  </code></pre>
  <p>What am I doing wrong?</p>