【问题标题】:Error creating Baseline Profile with Hilt WorkManager使用 Hilt WorkManager 创建基线配置文件时出错
【发布时间】:2022-11-14 10:00:25
【问题描述】:

我一直在努力在现有项目中创建 BaselineProfile。 Hilt WorkManager 配置和 BaselineProfileGenerator 之间似乎存在冲突。

每当我尝试生成配置文件时,都会收到以下错误:

...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)

为了运行 UI 测试并仍然让 WorkManager 注入 Hilt,我的应用程序如下所示:

@HiltAndroidApp
class MyApplication : BaseApplication() 

BaseApplication 看起来像这样:

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
    }
}

生成 BaselineProfile 的代码非常基础:

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

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

}

有没有人知道我还需要做什么才能使用这样的设置生成基线?

提前致谢!

【问题讨论】:

    标签: android-workmanager dagger-hilt baseline-profile


    【解决方案1】:

    这看起来不像 WorkManager 的问题,但对于 FirebaseRemoteConfigSettings,这是错误消息所指向的位置:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 2016-02-26
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多