Hello, Has anybody run into the navigation-compose...
# android
i
Hello, Has anybody run into the navigation-compose problem with hiltViewModel() ? I think it's all about dependencies.
not kotlin but kotlin colored 2
here is the error log:
Copy code
kotlin version: 2.1.20
error message: org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: /Users/sample/dev/android/projects/MyApp/features/auth/presentation/src/main/java/app/sample/auth/presentation/navigation/AuthNavGraph.kt
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:48)

...

Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call: CALL 'public final fun hiltViewModel$default <VM> (viewModelStoreOwner: androidx.lifecycle.ViewModelStoreOwner?, key: kotlin.String?, $mask0: <http://kotlin.Int|kotlin.Int>, $handler: kotlin.Any?): VM of androidx.hilt.navigation.compose.HiltViewModelKt.hiltViewModel$default [inline] declared in androidx.hilt.navigation.compose.HiltViewModelKt' type=VM of androidx.hilt.navigation.compose.HiltViewModelKt.hiltViewModel$default origin=DEFAULT_DISPATCH_CALL
Method: null
File is unknown
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.getMethodNode(SourceCompilerForInline.kt:128)

...

Caused by: java.lang.IllegalStateException: couldn't find inline method Landroidx/hilt/navigation/compose/HiltViewModelKt;.hiltViewModel$default(Landroidx/lifecycle/ViewModelStoreOwner;Ljava/lang/String;ILjava/lang/Object;)Landroidx/lifecycle/ViewModel;
	at org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.getMethodNode(SourceCompilerForInline.kt:128)
	at org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.loadCompiledInlineFunction(SourceCompilerForInline.kt:97)
	at org.jetbrains.kotlin.backend.jvm.codegen.IrSourceCompilerForInline.compileInlineFunction(IrSourceCompilerForInline.kt:92)
	at org.jetbrains.kotlin.codegen.inline.InlineCodegen.compileInline(InlineCodegen.kt:42)
	at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:50)
	... 70 more
Caused by: java.lang.IllegalStateException: couldn't find inline method hiltViewModel()
l
LoginScreen(viewmodel=viewmodel){
navController.navigate("signup")
}
You should pass in the viewmodel
i
I've tried it. didn't help. @Lan s
r
did you added
@HiltViewModel
annotation to your ViewModel?
i
@Robert Levonyan yes, I did.
Copy code
dagger.hilt.android.lifecycle.HiltViewModel
r
it's not recommended to use hiltViewModel() inside inline lambdas, try make the ViewModel as a parameter of you composable screen, also check the dependencies and versions, mb there's some mismatch
i
I've tried it, too. Where should I check for the matching versions of dependencies?
r
In your
build.gradle
file. Check both
hilt
and
ksp
versions
i
Copy code
hilt = "2.51.1"
hiltNavigationCompose = "1.2.0"
I haven't used
ksp
for hilt but if it helps:
Copy code
devtoolKsp = "2.1.20-1.0.32"
r
Copy code
hilt = "2.56.1"
ksp = "2.1.20-2.0.0"
try with those
i
same error
r
with viewmodel as a parameter?
l
add hilt-android-navigation = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "version" }
i
tried it, still not works @Robert Levonyan
I've added that. (not working) @Lan s
Copy code
hiltNavigationCompose = "1.2.0"
Could it be a problem with the Kotlin version and its incompatibility with the Hilt or Compose version?
r
try latest version of Kotlin
kotlin and ksp versions should match
i
both are latest version.
Copy code
kotlin = "2.1.20"
devtoolKsp = "2.1.20-2.0.0"
r
do you have only one module or it's multimodule project?
i
it's multimodule project
r
do you have same version of libs in all modules, also, did you applied ksp plugin to all modules?
i
yes and yes all modules read from version catalog plugin:
Copy code
alias(libs.plugins.google.dagger.hilt.android)
alias(libs.plugins.google.devtool.ksp)
dependencies:
Copy code
// hilt
    implementation(libs.hilt.android)
    implementation(libs.hilt.navigation.compose)
//    kapt(libs.google.hilt.compiler)
    ksp(libs.google.hilt.compiler)
r
that's very strange, I would suggest to also try instead of ksp use kapt or downgrade both hilt and ksp and check with lower versions
s
might be time to give Android Studio the ol' "Invalidate Caches & Restart"