kosi-libs / Kodein

Painless Kotlin Dependency Injection
https://kosi-libs.org/kodein
MIT License
3.21k stars 174 forks source link

'ModuleKt' crash appear in Kodein when using androidX #413

Closed superdiazzz closed 2 years ago

superdiazzz commented 2 years ago

Hi Kodein Team, i have a kind issue in internal kodein library. The issue logged in my crashlytics like below: Screen Shot 2022-07-11 at 09 41 39 written log below:

Fatal Exception: java.lang.VerifyError: Superclass androidx.core.app.f of androidx.activity.ComponentActivity is declared final (declaration of 'androidx.activity.ComponentActivity' appears in /data/app/mobile.android.tribun-wXwC_8sFAMNkqzRhTv7t9Q==/base.apk)
       at org.kodein.di.android.x.ModuleKt$androidXContextTranslators$1.invoke(ModuleKt.java:51)
       at org.kodein.di.android.x.ModuleKt$androidXContextTranslators$1.invoke(ModuleKt.java:2)
       at org.kodein.di.internal.DIBuilderImpl.import(DIBuilderImpl.java:123)
       at org.kodein.di.internal.DIBuilderImpl.importOnce(DIBuilderImpl.java:32)
       at org.kodein.di.DI$Builder$DefaultImpls.importOnce$default(DI.java:7)
       at org.kodein.di.android.x.ModuleKt$androidXModule$1.invoke(ModuleKt.java:12)
       at org.kodein.di.android.x.ModuleKt$androidXModule$1.invoke(ModuleKt.java:2)
       at org.kodein.di.internal.DIBuilderImpl.import(DIBuilderImpl.java:123)
       at org.kodein.di.DI$Builder$DefaultImpls.import$default(DI.java:7)
       at com.tribunnews.app.TribunNewsApplication$di$2.invoke(TribunNewsApplication.java:14)
       at com.tribunnews.app.TribunNewsApplication$di$2.invoke(TribunNewsApplication.java:2)
       at org.kodein.di.internal.DIImpl$Companion.newBuilder(DIImpl.java:5)
       at org.kodein.di.internal.DIImpl$Companion.access$newBuilder(DIImpl.java)
       at org.kodein.di.internal.DIImpl.<init>(DIImpl.java:7)
       at org.kodein.di.DI$Companion$lazy$1.invoke(DI.java:6)
       at org.kodein.di.DI$Companion$lazy$1.invoke(DI.java)
       at kotlin.SynchronizedLazyImpl.getValue(SynchronizedLazyImpl.java:20)
       at org.kodein.di.LazyDI.getBaseDI(LazyDI.java:2)
       at org.kodein.di.LazyDI.getContainer(LazyDI.java)
       at org.kodein.di.DIAwareKt$Instance$1.invoke(DIAwareKt.java:16)
       at org.kodein.di.DIAwareKt$Instance$1.invoke(DIAwareKt.java:4)
       at org.kodein.di.DIProperty$provideDelegate$1.invoke(DIProperty.java:54)
       at kotlin.SynchronizedLazyImpl.getValue(SynchronizedLazyImpl.java:20)
       at com.tribunnews.app.TribunNewsApplication.getCrashlytics(TribunNewsApplication.java:2)
       at com.tribunnews.app.TribunNewsApplication.onCreate(TribunNewsApplication.java:14)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
       at androidx.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:2)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
       at android.app.ActivityThread.access$1100(ActivityThread.java:199)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6669)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I use kodein version: implementation 'org.kodein.di:kodein-di-framework-android-x:7.2.0'

How can i solve this issue? thanks

romainbsl commented 2 years ago

Hello @superdiazzz

Do you have some more context to share, helping us to reproduce. Do you use specific bindings? scopes?

superdiazzz commented 2 years ago

Unfortunately i can not produce the crash. However, when i tested with similar type device i don't received any crash. This is how i initialize Kodein in my Application class Screen Shot 2022-07-11 at 18 51 49

also I need crashlytics reference inside onCreate (Application class), so i also call object di variables (CMIIW).

Screen Shot 2022-07-11 at 18 52 21

romainbsl commented 2 years ago

Not sure me can do something about this, as we can't reproduce it. This seems really context (device?) dependent.

However, might worth following this https://issuetracker.google.com/issues/237785592 This could be an R8 issue.

superdiazzz commented 2 years ago

Not sure me can do something about this, as we can't reproduce it. This seems really context (device?) dependent.

However, might worth following this https://issuetracker.google.com/issues/237785592 This could be an R8 issue.

Hi @romainbsl , i will try to figure out from this link. Speaking about my implementation before, does it correct if i call crashlytics params in onCreate of application? I don't see other sample implementation calling params instance inside application class (Always found in Activity or Fragment)

romainbsl commented 2 years ago

Sorry for the late response.

I don't think it matters where you call crashlytics, either from Application / Activity / Fragment is fine.

Just, in general, we must be careful with the lifecycles. Bit this is a another topic.