【发布时间】: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