osfans / trime

同文安卓輸入法平臺3.x/Android-rime/Rime Input Method Engine for Android
http://osfans.github.io/trime/
GNU General Public License v3.0
3.09k stars 372 forks source link

Crash on Koin #1199

Closed Bambooin closed 8 months ago

Bambooin commented 8 months ago

Describe the bug A clear and concise description of what the bug is.

Crash on Koin

To Reproduce Steps to reproduce the bug: I didn't find the 100% reproduce right now.

Expected behavior A clear and concise description of what you expected to happen.

Log If applicable, add crash log to quick focus your problem.

--------- Crash stacktrace
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:558)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    ... 1 more
Caused by: org.koin.core.error.KoinAppAlreadyStartedException: A Koin Application has already been started
    at org.koin.core.context.GlobalContext.register(GlobalContext.kt:44)
    at org.koin.core.context.GlobalContext.startKoin(GlobalContext.kt:63)
    at org.koin.core.context.DefaultContextExtKt.startKoin(DefaultContextExt.kt:40)
    at com.osfans.trime.ime.core.InputView.<init>(InputView.kt:49)
    at com.osfans.trime.ime.core.Trime.lambda$onCreateInputView$2$com-osfans-trime-ime-core-Trime(Trime.java:606)
    at com.osfans.trime.ime.core.Trime$$ExternalSyntheticLambda3.run(Unknown Source:2)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7924)
    ... 3 more

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

WhiredPlanck commented 8 months ago

@Bambooin I've had this problem before and now I know why. Input method service will recreate input view that make Koin started twice, I should startKoin in TrimeApplication, and just load the module when init input view and unload the module on it detached from window.