Git Product home page Git Product logo

Comments (1)

waqas7 avatar waqas7 commented on May 29, 2024

OK, I myself came up with a little modification to code. This might not be the right way but it does the job for me.

The Reason the No Class Def Found error occurs is because the CallScreeningService was introduced in Android N and hence the version below gets the runtime exception @https://developer.android.com/reference/kotlin/android/telecom/CallScreeningService

for Solution to this you have to create 2 different AppComponent's and ServiceBuilderModule's

  • This ServiceBuilderModule1 module is for Android N and above which has both abstract funtions i.e applockerService() & callBlockerService()

ServiceBuilderModule1

@Module
abstract class ServiceBuilderModule1 {

    @ContributesAndroidInjector
    abstract fun appLockerService(): AppLockerService

    @ContributesAndroidInjector
    abstract fun callBlockerService(): CallBlockerScreeningService

}
  • Now we have to create a second Module ServiceBuilderModule2 that will hold only appLocker() method. and this will be used when the API level < Android N. As CallScreeningService was introduced in AndroidN so we cannot use it below N.

ServiceBuilderModule2

@Module
abstract class ServiceBuilderModule2 {

    @ContributesAndroidInjector
    abstract fun appLockerService(): AppLockerService

}

  • Now create a copy of AppComponent. The only difference will be the replacement of ServiceBuilderModule1 & 2.

AppComponent

@Singleton
@Component(
    modules = [
        AndroidSupportInjectionModule::class,
        ActivityBuilderModule::class,
        ServiceBuilderModule1::class, <--- Replace ServiceBuilderModule2 in other i.e AppComponent2
        BroadcastReceiverBuilderModule::class,
        AppModule::class,
        DatabaseModule::class]
)
interface AppComponent2 : AndroidInjector<AppLockerApplication> {

    @Component.Builder
    abstract class Builder : AndroidInjector.Builder<AppLockerApplication>()

}
  • Now for the final touch Change the Override method androidInjector() in AppLockerApplication class like below.
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            return DaggerAppComponent.builder().create(this)
        return DaggerAppComponent2.builder().create(this)
    }

I hope this helps someone in someway and if i am wrong at this kindly do suggest a valid solution to this problem. for me i have tested this on Android 5.0 till Android 9 and it works just fine with this solution so i thought i should share it here

from applocker.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.