This message was deleted.
# koin
s
This message was deleted.
t
It sounds like a race condition
b
Whoops you replied as I was going to put last comment in my last message
A race condition in which way though?
t
Depends on when your
KoinComponent
implementations run
Is it related to
BroadcastReceivers
?
b
Is there an actual reason why anything inside a
KoinComponent
would not have access to Koin at any time once it’s been started? I do not have Koin in a broadcast receiver yet, but I was going too in the future. I understand in a broadcast receiver it might have not started yet, but when I test that I get a Koin not started error, not a NoBeanDefFound error Some of them are in the UI after onCreate has been called and after a network call has completed. One of them is in FirebaseMessagingService
t
Right. My fault sorry.
b
Actually, the current work i’m doing now has put one in a broadcast receiver, but it would be the first time and it’s not released.
t
Do you use scopes?
b
no, i haven’t dabbled in those yet
t
Which kinds of dependencies are problematic?
b
Not sure I understand the question? Like what am I trying to create and how?
So for example if an FCM message comes in I call this
Copy code
val notificationMessageRepo: NotificationMessageRepoApi by inject()

notificationMessageRepo.createNewMessage(fcmMessage)
This required a repo and a few other small things
t
I was wondering if there’s a rule which could be applied to the dependencies. But this exception might be thrown when there’s an issue creating the instance.
b
It’s not saying which inner part fails either, its just the whole object failed
so not like a remote source in
NotificationMessageRepoApi
is what failed
If it is an error creating one of inner ones, (which is maybe a repeat offender) it doesn’t give that detail which would be nice
t
Could you maybe post a complete stacktrace of the crash? Otherwise I’m out of ideas.
b
Sure, there’s a few different ways it looks, but gimmie a sec
Here’s one, just digging up a different one as well.
Copy code
Caused by org.koin.core.error.NoBeanDefFoundException
No definition found for class:'<myapp>.notificationmessage.NotificationMessageRepoApi'. Check your definitions!

org.koin.core.scope.Scope.throwDefinitionNotFound (Scope.kt:247)

org.koin.core.scope.Scope.resolveInstance (Scope.kt:216)

org.koin.core.scope.Scope.get (Scope.kt:181)

<myapp>.FcmListenerService$handleFcmMessage$$inlined$inject$1.invoke (ComponentCallbackExt.kt:51)

kotlin.UnsafeLazyImpl.getValue (Lazy.kt:81)

<myapp>.FcmListenerService.handleFcmMessage (FcmListenerService.kt:185)

<myapp>.FcmListenerService.onMessageReceived (FcmListenerService.kt:125)

com.google.firebase.messaging.FirebaseMessagingService.zzd (Unknown Source:67)

com.google.firebase.iid.zzb.run (Unknown Source:2)

java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)

java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)

com.google.android.gms.common.util.concurrent.zza.run (Unknown Source:6)

java.lang.Thread.run (Thread.java:764)
That’s happened 4-5 times? Probably over 20k hits a day
This one happens when trying to create my LogoutUnitOfWork which is in my old manual injection file and uses
get()
to access the Room database
Copy code
object Injector : KoinComponent {

@JvmStatic
fun provideDatabase(): Database {
    return get()
}
}
Copy code
Caused by org.koin.core.error.NoBeanDefFoundException
No definition found for class:'<myapp>.roomdatabase.Database'. Check your definitions!

org.koin.core.scope.Scope.throwDefinitionNotFound (Scope.kt:247)

org.koin.core.scope.Scope.resolveInstance (Scope.kt:216)

org.koin.core.scope.Scope.get (Scope.kt:181)

'<myapp>.Injector.provideDatabase (Injector.kt:685)

'<myapp>..Injector.provideLogoutUnitOfWork (Injector.kt:507)

'<myapp>.selflogout.SelfLogoutActivity.forceLogout (SelfLogoutActivity.java:129)

'<myapp>.selflogout.SelfLogoutActivity.onLogoutClicked (SelfLogoutActivity.java:221)

'<myapp>.selflogout.SelfLogoutActivity_ViewBinding$2.doClick (SelfLogoutActivity_ViewBinding.java:49)

butterknife.internal.DebouncingOnClickListener.onClick (DebouncingOnClickListener.java:18)

android.view.View.performClick (View.java:6294)

android.view.View$PerformClick.run (View.java:24774)

android.os.Handler.handleCallback (Handler.java:790)

android.os.Handler.dispatchMessage (Handler.java:99)

android.os.Looper.loop (Looper.java:164)

android.app.ActivityThread.main (ActivityThread.java:6518)

java.lang.reflect.Method.invoke (Method.java)

com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)

com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
The database one was also from the last release so it’s a new crash that’s happened a couple times now which isn’t promising for my next set of work
t
I’m out of ideas, sorry.
b
Thanks for taking a look.
👍 1
a
This happened 100% of time in case you have something scoped (like ViewModel) and you put
do not keep activities
in developer setting. I think it happened if app lives in background for a while and system kills it and after this user is trying to return back to the app via recent apps list.
this is what you see in this case
Also this is similar issue with https://github.com/InsertKoinIO/koin/issues/838 imo
b
I don’t think that’s what’s going on with my problem. I’m having issues for example with the user clicking a button on an already live activity. I’m not using scopes.
I also run my app with do not keep activities all the time, no crashes, as well as putting the app in the background, and killing the process (red square in logcat) and reopening the app. No crashes.