In my case, my custom view is in the library module i.e: ("com.android.library"), and I am using hilt in my App module i.e: ("com.android.application") due to this my application is crashing. because I am using the Hilt library in my App Module, and context instances are created by the Hilt library. and I am unable to find fragmentManger.
so as a workaround I have to add Hilt in my library module and then I used the below code to find the FragmentManger
private FragmentManager getFragmentManager(@NonNull Context mContext) {
if (mContext instanceof AppCompatActivity) {
return ((AppCompatActivity) mContext).getSupportFragmentManager();
} else if (mContext instanceof ContextThemeWrapper) {
return getFragmentManager(((ContextThemeWrapper) mContext).getBaseContext());
}
// below if clause is for hilt library
else if (mContext instanceof ViewComponentManager.FragmentContextWrapper) {
return getFragmentManager(((ViewComponentManager.FragmentContextWrapper) mContext).getBaseContext());
}
return null;
}
if this is the case Hope this should help someone.
happy coding.