RuntimeException AndroidInjection.inject in Dagger2 service

Viewed 190

I have a service and I'm using dagger2 v2.27, In the google play store consolo y have the following crash (I don't have this crash in Firebase console tho)

Caused by: java.lang.RuntimeException: at dagger.android.AndroidInjection.inject (AndroidInjection.java:124)
at app.ui.main.ServiceNotificationListener.onCreate (ServiceNotificationListener.java:34) at android.app.ActivityThread.handleCreateService (ActivityThread.java:3758)

I'm using a Service that extends Android NotificationListenerService , in onCreate I have the following

 override fun onCreate() {
        AndroidInjection.inject(this) // line 34
}

MainApplication:

    class MainApplication : Application(), HasAndroidInjector {
    
     override fun onCreate() {
            super.onCreate()
     DaggerAppComponent
                .builder()
                .application(this)
                .build()
                .inject(this)
    }
}

In AndroidManifest.xml

   <application
        android:hardwareAccelerated = "true"
        android:name=".ui.MainApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar.NoStatusBar">

I can't reproduce the bug, I reaad about the application is null, but not sure how I can solve the issue for my service (relies on NotificationListener) Thanks a lot

2 Answers

I wrote an article about this bug. Unless you know the actual problem, it's difficult to track or reproduce, and even harder to debug. It's an evil bug, and it is known to have driven at least one engineer to the brink of insanity. The article goes into detail about the actual issue.

TL;DR - Just set android:allowBackup=false, and that should fix your crashes.

....

I need another beer to drown out the memory of this bug now.

If possible share the code used in the NotificationListenerService. Since its a service i would prefer inject it inside the dagger module class.

Related