Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ComponentRuntime implements ComponentContainer, ComponentLoader {
private final Map<Qualified<?>, Provider<?>> lazyInstanceMap = new HashMap<>();
private final Map<Qualified<?>, LazySet<?>> lazySetMap = new HashMap<>();
private final List<Provider<ComponentRegistrar>> unprocessedRegistrarProviders;
private Boolean processedCoroutineDispatcherInterfaces = false;
private final EventBus eventBus;
private final AtomicReference<Boolean> eagerComponentsInitializedWith = new AtomicReference<>();
private final ComponentRegistrarProcessor componentRegistrarProcessor;
Expand Down Expand Up @@ -123,6 +124,24 @@ private void discoverComponents(List<Component<?>> componentsToAdd) {
}
}

// kotlinx.coroutines.CoroutineDispatcher interface could be provided by both new version of
// firebase-common and old version of firebase-common-ktx. In this scenario take the first
// interface which was provided.

Iterator<Component<?>> it = componentsToAdd.iterator();
while (it.hasNext()) {
Component component = it.next();
for (Object anInterface : component.getProvidedInterfaces().toArray()) {
if (anInterface.toString().contains("kotlinx.coroutines.CoroutineDispatcher")) {
if (processedCoroutineDispatcherInterfaces) {
iterator.remove();
break;
}
processedCoroutineDispatcherInterfaces = true;
}
}
}

if (components.isEmpty()) {
CycleDetector.detect(componentsToAdd);
} else {
Expand Down