microg/GmsCore · error · IllegalStateException
Failed to initialize CastContext.
Error message
Failed to initialize CastContext.
What it means
Wraps failure in CastContext.getOptionsProvider: the OPTIONS_PROVIDER_CLASS_NAME metadata could not be read from the app manifest or the named provider class could not be instantiated, so CastOptions cannot be obtained during CastContext creation.
Solutions
- Verify the OPTIONS_PROVIDER_CLASS_NAME metadata value matches a real, public, no-arg-instantiable class
- Ensure the class implements CastContext.OptionsProvider
- Catch the IllegalStateException and run without cast options
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at play-services-cast-framework/src/main/java/com/google/android/gms/cast/framework/CastContext.java:183 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/71c6a0fc0f04e442.
Report an issue: GitHub.
Appendix: source
Thrown at play-services-cast-framework/src/main/java/com/google/android/gms/cast/framework/CastContext.java:183
if (map.containsKey(sessionProvider.getCategory()))
throw new IllegalArgumentException("SessionProvider for category " + sessionProvider.getCategory() + " already added");
map.put(sessionProvider.getCategory(), sessionProvider.asBinder());
}
}
return map;
}
private static OptionsProvider getOptionsProvider(Context context) {
try {
Bundle metaData = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData;
String optionsProviderClassName = metaData.getString(OPTIONS_PROVIDER_CLASS_NAME_KEY);
if (optionsProviderClassName != null) {
return Class.forName(optionsProviderClassName).asSubclass(OptionsProvider.class).getDeclaredConstructor().newInstance();
}
throw new IllegalStateException("The fully qualified name of the implementation of OptionsProvider must be provided as a metadata in the AndroidManifest.xml with key com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME.");
} catch (PackageManager.NameNotFoundException | ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException |
InvocationTargetException | NullPointerException e) {
throw new IllegalStateException("Failed to initialize CastContext.", e);
}
}
@NonNull
DiscoveryManager getDiscoveryManager() {
return discoveryManager;
}
}
View on GitHub (pinned to 157c9d86ac)