[FIXED] error: [Dagger/MissingBinding] @com.zhixin.wedeep.common.di.LoginApi okhttp3.OkHttpClient cannot be provided without an @Provides-annotated method


When i executed my test code with hilt, i got above error. Which is quite werid, because everything run well in my app.

The following is my test code.

class TestHomePageFragment {

    private val intent = Intent(ApplicationProvider.getApplicationContext(), AudioPlayerActivity::class.java).apply {
        flags = Intent.FLAG_ACTIVITY_NEW_TASK
     val activityRule:ActivityScenarioRule<AudioPlayerActivity> = activityScenarioRule(intent)
    var hiltRule = HiltAndroidRule(this)

    fun init(){

    fun testVote(){
//        Assert.assertEquals(1,1)
        val scenario = activityRule.scenario


My component module

object NetWorkModule {

    fun provideOkHttpClient(interceptor: HttpLoggingInterceptor): OkHttpClient =

    fun provideLoggingInterceptor() =
            HttpLoggingInterceptor().apply { level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE }

    fun provideGson(): Gson = Gson()

    fun provideGsonConverterFactory(gson: Gson): GsonConverterFactory =

    fun provideCoroutineScopeIO() = CoroutineScope(Dispatchers.IO)

Any ideas for this problem?


No this is not weird because you are trying to use dagger-hilt modules with a normal Activity that is not annotated with @AndroidEntryPoint.

Please refer to this tutorial as it explains how to test fragments with dagger-hilt: https://www.youtube.com/watch?v=k4zG93ogWFY&t

Answered By – Andrew

Answer Checked By – Candace Johnson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published