7

I have been receiving this error on Dagger-Hilt and I don't know why, I even downgraded to a simple project to see if I could find my problem, but apparently I am doing everything correctly. I created the Application class, declared it on the Manifest file, created a single Module that provides a String and I get the error when I try to inject it on the main activity, the error says "D:\Programacion\Kotlin\TryingHilt\app\build\tmp\kapt3\stubs\debug\com\y4kuzabanzai\tryinghilt\MainActivity.java:7: error: [Hilt] public final class MainActivity extends androidx.appcompat.app.AppCompatActivity { ^ @EntryPoint com.y4kuzabanzai.tryinghilt.MainActivity must also be annotated with @InstallIn [Hilt] Processing did not complete. See error above for details."

Here my code:

Application Class

@HiltAndroidApp
class MyApp : Application() {
}

Module class

@Module
@InstallIn(ApplicationComponent::class)
class TestModule {

    @Singleton
    @Provides
    fun providesString(): String {
        return "Something"
    }
}

MainActivity Class

@EntryPoint
class MainActivity : AppCompatActivity() {

    @Inject
    lateinit var injectedString: String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Log.d("MyTag", "onCreate: $injectedString")
    }
}
Tony
  • 159
  • 1
  • 11

1 Answers1

9

You should you @AndroidEntryPoint here with the activity. @Entrypoint used for some different purpose and its not the right use.

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

    @Inject
    lateinit var injectedString: String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Log.d("MyTag", "onCreate: $injectedString")
    }
}
0xAliHn
  • 18,390
  • 23
  • 91
  • 111
  • But is the way they say you should use it, how must I do this then? – Tony Jun 08 '21 at 14:55
  • Nope this is the link for which `@EntryPoint` used for https://dagger.dev/hilt/entry-points. For your case you should use `@AndroidEntryPoint` – 0xAliHn Jun 08 '21 at 14:57
  • Thank you so much Sir!! I feel so stupid, I read it wrong, thanks a million times – Tony Jun 08 '21 at 15:03