google/dagger

Can't add Hilt to a multiplatform project

mylesbennett opened this issue · 4 comments

This was first raised here when I was trying to add Hilt to a multiplatform project using the traditional kapt annotation processor. I switched to the latest KSP arrangement and now have a new error on build:

[ksp] /composeApp/src/androidMain/kotlin/com/bpp/example/MainActivity.kt:12: [Hilt] Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin? (com.google.dagger.hilt.android)
See https://dagger.dev/hilt/gradle-setup.html
[1;31m[Hilt] Processing did not complete. See error above for details. [0m

Here is a repo demonstrating the problem.

Hi, @mylesbennett , thanks for reporting. This looks similar to this one: #4130. Could you give the latest snapshot a try?

Hi @kuanyingchou, Thanks for your quick reply.

I tried the snapshot arrangement - still the same error.

It's possible there was something lost in my translating the Groovy instructions to Kotlin DSL/ Version Catalogs.
Also the instructions were for Dagger, but the resolution strategy seemed to pick up the snapshots for Hilt as well. At least, that was what the download report suggested on build.

Here is my attempt:
https://github.com/mylesbennett/Compose-Multiplatform-Hilt-Kapt-type-mismatch/tree/dagger-snapshot
(BTW, ignore the title of repo. I gave up on kapt and switched to ksp)

Hi, @mylesbennett , you also need to move Hilt to "HEAD-SNAPSHOT" in your libs.versions.toml, and add maven("https://oss.sonatype.org/content/repositories/snapshots") to both repositories in your settings.gradle.kts.

Odd. The first time I attempted to move Hilt to "HEAD-SNAPSHOT", the build said it couldn't find the libraries.
Maybe adding the maven snapshot in settings.gradle.kts is what made the difference. That bit wasn't in the "latest snapshot" intstructions.

Anyhow, thanks, that seems fixed. I pushed the changes to that branch for anyone intrrested.

What official version can I document that this will be fixed in (ie, when will it be released)?