Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hilt: Injection not working in BroadcastReceiver #4379

Open
BurningDroid opened this issue Aug 6, 2024 · 5 comments
Open

Hilt: Injection not working in BroadcastReceiver #4379

BurningDroid opened this issue Aug 6, 2024 · 5 comments

Comments

@BurningDroid
Copy link

BurningDroid commented Aug 6, 2024

I have an app that has been running for 3 years.
I have implemented and am using BroadcastReceiver.

I recently updated the hilt version from 2.45.0 to 2.51.0.
After the update, Firebase Crashlytics started showing an explosion of new crashes.
These are completely new crashes that were never there before.

@AndroidEntryPoint
class AlarmReceiver : BroadcastReceiver() {

    @Inject
    lateinit var notificationManager: NotificationManagerCompat
    @Inject
    lateinit var getUsers: GetUsers

    override fun onReceive(context: Context, intent: Intent) {
        // do something

        getUsers.get() // *** CRASH HERE ***

        // do something
    }
}

The crash is:

Fatal Exception: kotlin.UninitializedPropertyAccessException
lateinit property getUsers has not been initialized

Nothing has changed in the hilt settings.
Only the version has changed, and the AlarmReceiver was working fine before.
What could be the bug in 2.51.0?

@bcorso
Copy link

bcorso commented Aug 7, 2024

lateinit property getPortfolios has not been initialized

What is this property? Is this something in your code (I don't see it in the AlarmReceiver you posted)? Is it an @Inject property?

@BurningDroid
Copy link
Author

lateinit property getPortfolios has not been initialized

What is this property? Is this something in your code (I don't see it in the AlarmReceiver you posted)? Is it an @Inject property?

Oh sorry, I updated the error log

@bcorso
Copy link

bcorso commented Aug 8, 2024

Hmm, this suggests that maybe the bytecode injection isn't working properly.

Does it work if you extend the hilt class manually (see changes below)?

-@AndroidEntryPoint
+@AndroidEntryPoint(BroadcastReceiver::class)
-class AlarmReceiver : BroadcastReceiver() { ... }
+class AlarmReceiver : Hilt_BroadcastReceiver() { ... }

@tdnghia98
Copy link

Same here, I also have this issue

@CodingWithTashi
Copy link

I had the same issue but in my case, I was using

 // Dagger Hilt
    implementation 'com.google.dagger:hilt-android:2.52'
    kapt 'com.google.dagger:hilt-compiler:2.52'

Issue was due to class path version in project level build.gradle file
classpath 'com.google.dagger:hilt-android-gradle-plugin:44'
update to
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.52'
make sure all are in same version i.e 2.52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants