Comments (5)
One thing that strikes me a bit odd is that your have implementation(libs.hilt.plugin)
which I understand as your project depending on the Hilt Gradle plugin as if it was a library with APIs to be used in your project but thats not quite how a Gradle Plugin is applied. Can you confirm you are indeed applying the plugin as described in https://dagger.dev/hilt/gradle-setup.html, either with the apply plugin
syntax or the newer plugins
DSL.
In essence HiltWorkerFactory
is a multibinding of all @HiltWorker
annotated so if you debug and breakpoint inside the factory you should see a map where you can confirm if the worker is in the map a signal that the multibinding module was picked up and generated. If you don't see it then either the @InstallIn
module based of the @HiltWorker
is not being generated or the multibinding is not being discovered because it is not a direct dependency of the app module or it is a transitive dependency but the Hilt Gradle Plugin which does aggregation is not being applied.
from dagger.
I am applying the plugin like this...
root build.gradle
buildscript {
repositories {
google()
mavenCentral()
jitpack()
}
dependencies {
classpath(libs.kotlingradleplugin)
classpath(libs.gradleplugin)
classpath(libs.play.services)
classpath(libs.undercouch.download)
classpath(libs.firebase.plugins)
classpath(libs.hilt.plugin)
classpath(libs.firebase.crashlytics.gradle)
classpath(libs.paparazzi.gradle)
}
}
plugins {
id("com.google.dagger.hilt.android") version "2.44.2" apply false
}
And in :app
and :core-ble
module...
plugins {
id("com.android.application") //this is just in :app
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
id("kotlin-parcelize")
id("dagger.hilt.android.plugin")
id("com.google.dagger.hilt.android")
}
I debugged HiltWorkerFactory
and the map is empty. So how can this be fixed in feature modules?
from dagger.
Can you please clarify if :core-ble
is a feature module as described in https://developer.android.com/guide/playcore/feature-delivery? If that is the case, then sadly having a Hilt worker in such module is not supported as those modules cannot be correctly aggregated as described in https://developer.android.com/training/dependency-injection/hilt-multi-module#dfm
If it is just a library module, as in a Gradle module, then can you try having :app
directly depend on :core-ble
?
from dagger.
Sorry it's not. It's just a module implemented by :app
from dagger.
I ended up writing my own WorkerFactory and injecting the necessary parameters there...
class BleWorkerFactory @Inject constructor(
private val bleServiceModule: BleServiceModule,
) : WorkerFactory() {
override fun createWorker(appContext: Context, workerClassName: String, workerParameters: WorkerParameters): ListenableWorker? {
return when (workerClassName) {
RemoteConfigSyncWorker::class.java.name -> RemoteConfigSyncWorker(appContext, workerParameters)
HardwareReportWorker::class.java.name -> HardwareReportWorker(appContext, workerParameters, bleServiceModule)
ActivitySyncWorker::class.java.name -> ActivitySyncWorker(appContext, workerParameters, bleServiceModule)
else -> null
}
}
}
@Singleton
class MyDelegatingWorkerFactory @Inject constructor(
bleWorkerFactory: BleWorkerFactory
) : DelegatingWorkerFactory() {
init {
addFactory(bleWorkerFactory)
}
}
In my application I do not implement Configuration.Provider since I got a RuntimeException: Unable to instantiate application
when overriding the workManagerConfiguration val. Instead I set the configuration in onCreate().
@HiltAndroidApp
open class RandomHiltApplication : MyApplication() {
@EntryPoint
@InstallIn(SingletonComponent::class)
interface WorkerFactoryEntryPoint {
fun workerFactory(): MyDelegatingWorkerFactory
}
override fun onCreate() {
val workManagerConfiguration: Configuration = Configuration.Builder()
.setWorkerFactory(EntryPoints.get(this, WorkerFactoryEntryPoint::class.java).workerFactory())
.setMinimumLoggingLevel(Log.VERBOSE)
.build()
WorkManager.initialize(this, workManagerConfiguration)
super.onCreate()
}
}
My Fastlane builds are now working and I am happy with it. Sadly, I couldn't find out, why the HiltWorkerFactory is not working.
from dagger.
Related Issues (20)
- Multibinding with Nested Complex Keys uses the wrong AnnotationCreator HOT 1
- [Hilt] onCreate() in my Application doesn't called on Instrument test HOT 4
- [Dagger-Hilt] Error when applying obfuscation other than Proguard (Allatori) HOT 3
- error: [Hilt] Expected @AndroidEntryPoint to have a value HOT 3
- @IntoSet analog for injectable classes HOT 3
- Hilt Generated Code having not used code? HOT 2
- [Dagger-Hilt] Can't get viewModel in composable by Hilt HOT 1
- Why does Provides in a Companion Object work? HOT 6
- Update Dagger guava dependency to address CVE-2023-2976 HOT 2
- Add KMP support for @HiltViewModel annotation HOT 2
- Dagger resolution and dynamic feature module HOT 1
- Feature request: Manually regenerate application component HOT 1
- Using TestContainer.com HOT 2
- Detect dependency cycles containing Lazy or Provider during the compilation time HOT 6
- error when ksp.useKSP2=true HOT 2
- Suppress annotation on @Inject is not honored on the Factory HOT 1
- [KSP2] Dagger and Hilt incompatibility with KSP2 HOT 2
- [KSP2] NullPointerException: null cannot be cast to non-null type androidx.room.compiler.processing.XType HOT 1
- App crashing with NPE for some classes when Lazy Class Key is used HOT 6
- OutOfMemoryError with Maven HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dagger.