dagger-workmanager's People
Forkers
morristech aungtuntun ablenesi cxl086 nqnhat1988 louislin0706 gopineelam1925 sapigila shakil807g paolomanca derekwasswa ayoubbk arthurdcarvalho sagamornord mastrgamrdagger-workmanager's Issues
Upgrading WorkManager to latest version (2.6.0.XX) breaks the functionality !
I am trying to use Work manager with the latest versions but it seems to work only till 2.5.0.
I am not sure if something broke for 2.6.0.XX versions.
The issue is only with HelloWorldWorker.
Find the logs below :
2021-07-23 23:38:15.983 17783-17910/com.sample.daggerworkmanagersample E/WM-WorkerFactory: Could not instantiate com.sample.daggerworkmanagersample.HelloWorldWorker
java.lang.NoSuchMethodException: <init> [class android.content.Context, class androidx.work.WorkerParameters]
at java.lang.Class.getConstructor0(Class.java:2327)
at java.lang.Class.getDeclaredConstructor(Class.java:2166)
at androidx.work.WorkerFactory.createWorkerWithDefaultFallback(WorkerFactory.java:95)
at androidx.work.impl.WorkerWrapper.runWorker(WorkerWrapper.java:244)
at androidx.work.impl.WorkerWrapper.run(WorkerWrapper.java:136)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
2021-07-23 23:38:15.983 17783-17910/com.sample.daggerworkmanagersample E/WM-WorkerWrapper: Could not create Worker com.sample.daggerworkmanagersample.HelloWorldWorker
While the DaggerAndroidWorker
seems to work fine!
androidInjector has not been initialized
Hello. I'm having an issue starting up my second worker that uses the ContextInjector
class.
dagger2 version: 2.28
assisted inject version: 0.5.2
I'm getting:
2020-06-07 10:07:09.009 5632-5895/com.company.myapp E/WM-WorkerFactory: Could not instantiate com.company.myapp.tasks.VideoBorderWorker
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at androidx.work.WorkerFactory.createWorkerWithDefaultFallback(WorkerFactory.java:96)
at androidx.work.impl.WorkerWrapper.runWorker(WorkerWrapper.java:242)
at androidx.work.impl.WorkerWrapper.run(WorkerWrapper.java:136)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property androidInjector has not been initialized
at com.company.myapp.MainApplication.androidInjector(MainApplication.kt:30)
at com.company.myapp.tasks.ContextInjection.inject(VideoBorderWorker.kt:22)
at com.company.myapp.tasks.VideoBorderWorker.<init>(VideoBorderWorker.kt:30)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at androidx.work.WorkerFactory.createWorkerWithDefaultFallback(WorkerFactory.java:96)
at androidx.work.impl.WorkerWrapper.runWorker(WorkerWrapper.java:242)
at androidx.work.impl.WorkerWrapper.run(WorkerWrapper.java:136)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
2020-06-07 10:07:09.009 5632-5895/com.company.myapp E/WM-WorkerWrapper: Could not create Worker com.company.myapp.tasks.VideoBorderWorker
I have a main MainApplication
component:
class MainApplication : Application(), Configuration.Provider, HasAndroidInjector {
@Inject
lateinit var androidInjector: DispatchingAndroidInjector<Any>
@Inject
lateinit var appComponent: ApplicationComponent
override fun onCreate() {
appComponent = DaggerApplicationComponent.create()
appComponent.inject(this)
super.onCreate()
}
override fun androidInjector(): AndroidInjector<Any> {
return androidInjector
}
override fun getWorkManagerConfiguration(): Configuration {
val factory: DiInjectWorkerFactory = appComponent.factory()
return Configuration.Builder().setWorkerFactory(factory).build()
}
}
My ApplicationComponent
interface:
@Component(
modules = [
AndroidInjectionModule::class,
VideoBorderWorker.Module::class,
SampleAssistedInjectModule::class,
WorkerBindingModule::class,
MainModule::class
]
)
interface ApplicationComponent : AndroidInjector<Application> {
fun factory(): DiInjectWorkerFactory
fun inject(videoPublishActivity: VideoPublishActivity)
}
@Module(includes = [AssistedInject_SampleAssistedInjectModule::class])
@AssistedModule
interface SampleAssistedInjectModule
@MapKey
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class WorkerKey(val value: KClass<out ListenableWorker>)
@Module
interface WorkerBindingModule {
@Binds
@IntoMap
@WorkerKey(ResizeVideoWorker::class)
fun bindResizeVideoWorker(factory: Factory): ChildWorkerFactory
}
ResizeVideoWorker
:
class ResizeVideoWorker @AssistedInject constructor(
@Assisted private val appContext: Context,
@Assisted private val params: WorkerParameters,
private val projectFileService: ProjectFileService,
private val ffmpegService: FfmpegService
) : Worker(appContext, params) {
...
@AssistedInject.Factory
interface Factory : ChildWorkerFactory
}
interface ChildWorkerFactory {
fun create(appContext: Context, params: WorkerParameters): ListenableWorker
}
And VideoBorderWorker
:
object ContextInjection {
@JvmStatic
fun inject(to: Any, with: Context) {
(with.applicationContext as HasAndroidInjector).androidInjector().inject(to)
}
}
class VideoBorderWorker constructor(context: Context, params: WorkerParameters) : Worker(context, params) {
@Inject lateinit var ffmpegService: FfmpegService
init {
ContextInjection.inject(to = this, with = context)
}
...
@dagger.Module
interface Module {
@ContributesAndroidInjector
fun worker(): VideoBorderWorker
}
}
what about Worker that don't need injection
In my project, I have a Worker which needs DI
class SyncWorker @AssistedInject constructor(
@Assisted private val appContext: Context,
@Assisted private val params: WorkerParameters,
private val userManager: UserManager
): CoroutineWorker(appContext, params)
and it works great with your solution
but I also have a Worker that use the default constructor
class SchedulerWorker (
private val appContext: Context,
private val params: WorkerParameters
): Worker(appContext, params)
and when this Worker needs to be instantiated by the WorkManager IllegalArgumentException("unknown worker class name: $workerClassName")
from the WorkerFactory kicks in
how to solve that ?
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.