microg/GmsCore · error · IllegalArgumentException

SessionProvider for category already added

Error message

SessionProvider for category  already added

What it means

CastContext.getSessionProviderMap rejects duplicate session-provider categories: when an additional SessionProvider declares a category already mapped (the built-in cast session provider's category), IllegalArgumentException is thrown during CastContext construction.

Source

Thrown at play-services-cast-framework/src/main/java/com/google/android/gms/cast/framework/CastContext.java:166

            this.discoveryManager = new DiscoveryManager(appContext, delegate.getDiscoveryManagerImpl());
        } catch (RemoteException e) {
            throw new IllegalStateException("Failed to call dynamite module", e);
        }
    }

    private Map<String, IBinder> getSessionProviderMap() {
        Map<String, IBinder> map = new HashMap<>();
        if (castSessionProvider != null) {
            map.put(castSessionProvider.getCategory(), castSessionProvider.asBinder());
        }
        List<SessionProvider> list = this.additionalSessionProviders;
        if (list != null) {
            for (SessionProvider sessionProvider : list) {
                if (sessionProvider == null) throw new IllegalArgumentException("Additional SessionProvider must not be null.");
                if (sessionProvider.getCategory() == null || sessionProvider.getCategory().isEmpty())
                    throw new IllegalArgumentException("Category for SessionProvider must not be null or empty string.");
                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);
        }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Assign each SessionProvider a distinct category string
  2. Remove the duplicate provider from additionalSessionProviders
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at play-services-cast-framework/src/main/java/com/google/android/gms/cast/framework/CastContext.java:166 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/c121c42edf830bdb. Report an issue: GitHub.