androidkotlinfirebase-job-dispatcher

Type inference failed. Firebase JobDispatcher


I'm facing the following error on this line: .setService(LocationFirebaseJobService::class.java):

Type inference failed. Expected type mismatch: inferred type is Class<LocationFirebaseJobService> but Class<out JobService!> was expected

Here is my code:

val dispatcher = FirebaseJobDispatcher(GooglePlayDriver(context))

            val myJob = dispatcher.newJobBuilder()
                    .setService(LocationFirebaseJobService::class.java)         
                    .setTag("my-unique-tag")                                    
                    .build()

My LocationFirebaseJobService class:

class LocationFirebaseJobService: JobService() {

    override fun onStartJob(p0: JobParameters?): Boolean {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onStopJob(p0: JobParameters?): Boolean {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

}

Solution

  • Are you sure that you extend proper JobService? Firebase provides com.firebase.jobdispatcher.JobService but Android after API level 21 provides android.app.job.JobService (Firebase is compat version of this API)

    Check your imports in LocationFirebaseJobService