https://kotlinlang.org logo
#koin-contributors
Title
# koin-contributors
o

Omar Mainegra

10/06/2020, 5:12 PM
Hi, I was trying RC (
2.2.0-rc-1
) but I got some crashes
It's not happening in
2.1.6
Copy code
Caused by: java.lang.IllegalStateException: You can consumeRestoredStateForKey only after super.onCreate of corresponding component
        at androidx.savedstate.SavedStateRegistry.consumeRestoredStateForKey(SavedStateRegistry.java:77)
        at androidx.lifecycle.SavedStateHandleController.create(SavedStateHandleController.java:67)
        at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:67)
        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:185)
        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
        at org.koin.androidx.viewmodel.ViewModelResolverKt.get(ViewModelResolver.kt:23)
        at org.koin.androidx.viewmodel.ViewModelResolverKt.resolveInstance(ViewModelResolver.kt:12)
        at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel(ScopeExt.kt:85)
        at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel(ScopeExt.kt:71)
        at org.koin.androidx.viewmodel.koin.KoinExtKt$getViewModel$1.invoke(KoinExt.kt:40)
        at org.koin.androidx.viewmodel.koin.KoinExtKt$getViewModel$1.invoke(Unknown Source:2)
        at org.koin.core.Koin.onScopeRegistry(Koin.kt:47)
        at org.koin.androidx.viewmodel.koin.KoinExtKt.getViewModel(KoinExt.kt:40)
        at org.koin.androidx.viewmodel.ext.android.FragmentExtKt.getViewModel(FragmentExt.kt:72)
        at components.PasswordComponentFragment$$special$$inlined$viewModel$2.invoke(FragmentExt.kt:74)
        at components.PasswordComponentFragment$$special$$inlined$viewModel$2.invoke(Unknown Source:0)
        at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
        at components.PasswordComponentFragment.getVm(Unknown Source:2)
        at components.PasswordComponentFragment.onInflate(PasswordComponent.kt:137)
        at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:106)
        at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:237)
        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1059)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
        at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
        at fragments.SignUpWithEmailFragment.onCreateView(SignUpWithEmailFragment.kt:103)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2699)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1199)
        at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2236)
2020-10-06 12:02:28.999 5324-5324/E/AndroidRuntime:     at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2009)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1965)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861)
        at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
My version of
androidx.fragment
is
1.2.5
a

arnaud.giuliani

10/07/2020, 9:48 AM
can you show your code?
perhaps some changes are breaking in androidx.fragment? 🤔
o

Omar Mainegra

10/07/2020, 2:24 PM
Let me try to reproduce outside our app, also let I could try to scope the actual version
a

arnaud.giuliani

10/07/2020, 2:43 PM
ok thanks 👍
o

Omar Mainegra

10/07/2020, 3:54 PM
I found it started failing in
2.2.0-beta-1
I think it could be related to having a fragment with a VM (using
by viewModel()
) inside another fragment with VM as well
a

arnaud.giuliani

10/07/2020, 4:05 PM
your stacktrace doesn’t reflect Koin 🤔
o

Omar Mainegra

10/07/2020, 4:08 PM
Copy code
org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel
?
a

arnaud.giuliani

10/07/2020, 4:08 PM
oups yes
can you have a snippet to reproduce that?
o

Omar Mainegra

10/07/2020, 4:11 PM
Let me prepare something, sure
a

arnaud.giuliani

10/07/2020, 4:13 PM
this will help investigate
o

Omar Mainegra

10/07/2020, 7:00 PM
It turns out I'm using the VM in
onInflate
(getting some XML attributes and send the values to the VM) that's causing the crash in 2.2, I refactored use the VM in
onCreateView
and it's working fine, I don't know if it's worth to open an issue
a

arnaud.giuliani

10/08/2020, 7:20 AM
I believe the factory VM is not “ready” yet. Yes, avoid use it before onCreate/onCreateView
personally, I use it in onViewCreated for fragments
9 Views