I got following crash in crashlytics, but cannot reproduce issue. There is no exception explanation which I can use to trace:
dagger.hilt.internal.Preconditions.checkState (Preconditions.java:83)
com.xxx.xxx.ui.base.Hilt_BaseFragment.onAttach (Hilt_BaseFragment.java:46)
androidx.fragment.app.Fragment.onAttach (Fragment.java:1783)
com.xxx.xxx.ui.base.Hilt_BaseFragment.onAttach (Hilt_BaseFragment.java:36)
androidx.fragment.app.Fragment.performAttach (Fragment.java:2922)
androidx.fragment.app.FragmentStateManager.attach (FragmentStateManager.java:464)
In BaseFragment, there are some injected objects.
@AndroidEntryPoint
abstract class BaseFragment : FragmentForLifeCycles() {
@Inject
lateinit var injectedClass: InjectedClass
}
There is no retained fragment (I mean there is no setRetainInstance(true) for the fragments)
In some of the fragments which are derived from BaseFragment are annotated with @AndroidEntryPoint or not according to the needing of injection on that fragment.
Here is the generated hilt class (Hilt_BaseFragment.java) onAttach block where the error is occurred;
@Override
@CallSuper
@MainThread
public void onAttach(Activity activity) {
super.onAttach(activity);
Preconditions.checkState(componentContext == null || FragmentComponentManager.findActivity(componentContext) == activity, "onAttach called multiple times with different Context! Hilt Fragments should not be retained.");
initializeComponentContext();
inject();
}