androidandroid-jetpack-composebuild.gradleandroid-jetpackjetpack-compose-navigation

NoSuchMethodError in Jetpack Compose Navigation


Stacktrace


java.lang.NoSuchMethodError: No virtual method setScreen()Lkotlin/jvm/functions/Function3; 
in class Lcom/example/app/presentation/navigation/Screen$ExampleScreen; 
or its super classes (declaration of 'com.example.app.presentation.navigation.Screen$ExampleScreen' 
appears in /data/data/com.example.app.dev/code_cache/.overlay/base.apk/classes2.dex)
at com.example.app.presentation.navigation.NavigationManagerKt$NavigationManager$1.invoke(NavigationManager.kt:242)
at com.example.app.presentation.navigation.NavigationManagerKt$NavigationManager$1.invoke(NavigationManager.kt:34)
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:382)
...

Occurrence

When setting up a screen in the navhost in Jetpack compose

Screen.ExampleScreenObject.let { screen ->
   composable(
      route = screen.getFullRoute(),
      arguments = screen.getArgs(),
      content = screen.screen
  )
}

where screen.screen is of type @Composable (NavBackStackEntry) -> Unit

Otherwise if I call the screen composable directly it does not occur

Screen.ExampleScreenObject.let { screen ->
   composable(
      route = screen.getFullRoute(),
      arguments = screen.getArgs(),
      content = {
          ExampleScreen()
      }
  )
}

Versions

compose : 1.5.2
navigation-compose : 2.7.3
kotlin compose: 1.8.22
(I'll add more if need be)

EDIT

I am also experiencing a similar issue with the NavController

java.lang.NoSuchMethodError: No virtual method getBackQueue()Lkotlin/collections/ArrayDeque; 
in class Landroidx/navigation/NavHostController; 
or its super classes (declaration of 'androidx.navigation.NavHostController' a
ppears in /data/app/~~HJSBJgaTbw4Lze-D4uCIwQ==/com.example.app.dev-i2HpxAmhqkk6Wwv7O0dNxg==/base.apk!classes32.dex)

at com.example.app.presentation.navigation.NavigatorImpl.logBackStack(NavigatorImpl.kt:21)
at com.example.app.presentation.navigation.NavigatorImpl.access$logBackStack(NavigatorImpl.kt:8)
at com.example.app.presentation.navigation.NavigatorImpl$1.onDestinationChanged(NavigatorImpl.kt:14)
at androidx.navigation.NavController.dispatchOnDestinationChanged(NavController.kt:1002)
at androidx.navigation.NavController.navigate(NavController.kt:1859)
at androidx.navigation.NavController.onGraphCreated(NavController.kt:1283)
at androidx.navigation.NavController.setGraph(NavController.kt:1195)
at androidx.navigation.NavController.setGraph(NavController.kt:100)
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:225)
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:83)
...

Solution

  • The culprits were these two dependencies

    implementation ("androidx.navigation:navigation-fragment-ktx:2.5.3")
    implementation ("androidx.navigation:navigation-ui-ktx:2.5.3")
    

    Specifically the versions

    Up them to match navigation-compose versions 2.7.3