Error creating Baseline Profile with Hilt WorkManager

118 Views Asked by At

I've been struggling to create a BaselineProfile in my existing project. There seems to be a conflict between the Hilt WorkManager configuration and the BaselineProfileGenerator.

Whenever I try to generate the profile I get the following error:

...MyApplication_HiltComponents.java:192: error: [Dagger/MissingBinding] com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings cannot be provided without an @Inject constructor or an @Provides-annotated method.
  public abstract static class SingletonC implements BaseApplication.WorkerFactoryEntryPoint,
                         ^
      com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings is injected at
          {redacted package}.ApplicationModule.provideFirebaseRemoteConfig(settings)

In order to run UI tests and still having WorkManager injected with Hilt my application looks like this:

@HiltAndroidApp
class MyApplication : BaseApplication() 

And the BaseApplication looks like this:

open class BaseApplication : Application(), Configuration.Provider {

    private val workerFactory by lazy {
        EntryPointAccessors.fromApplication(applicationContext, WorkerFactoryEntryPoint::class.java)
            .getWorkerFactory()
    }

    override fun getWorkManagerConfiguration(): Configuration {
        return Configuration.Builder().setWorkerFactory(workerFactory).build()
    }

    @EntryPoint
    @InstallIn(SingletonComponent::class)
    interface WorkerFactoryEntryPoint {
        fun getWorkerFactory(): HiltWorkerFactory
    }
}

The code to generate the BaselineProfile is very basic:

@OptIn(ExperimentalBaselineProfilesApi::class)
class BaselineProfileGenerator {
@get:Rule(order = 1)
val baselineProfileRule = BaselineProfileRule()

@Test
fun generate() = baselineProfileRule.collectBaselineProfile(
    packageName = MY_PACKAGE
) {
    pressHome()
    startActivityAndWait()
}

}

Does anyone have any ideas what else I need to do to generate a baseline with such a setup?

Thanks in advance!

1

There are 1 best solutions below

1
On BEST ANSWER

This doesn't look like a problem with WorkManager but with FirebaseRemoteConfigSettings, given that's where the error message is pointing to:

error: [Dagger/MissingBinding] ...FirebaseRemoteConfigSettings cannot be provided without an @Inject constructor or an @Provides-annotated method.