material-components/material-components-android · error · IllegalArgumentException

Non color resource found: name={name}, typeId={typeId}

Error message

Non color resource found: name={name}, typeId={typeId}

What it means

While iterating the color mapping, the creator resolves each resource ID's type name via Resources.getResourceTypeName and requires it to be 'color'. Any ID of another type (string, dimen, drawable) is rejected with IllegalArgumentException including the offending name and type id, because the generated table can only remap color entries.

Source

Thrown at lib/java/com/google/android/material/color/ColorResourcesTableCreator.java:87

    if (colorMapping.entrySet().isEmpty()) {
      throw new IllegalArgumentException("No color resources provided for harmonization.");
    }
    PackageInfo applicationPackageInfo =
        new PackageInfo(APPLICATION_PACKAGE_ID, context.getPackageName());

    Map<PackageInfo, List<ColorResource>> colorResourceMap = new HashMap<>();
    ColorResource colorResource = null;
    for (Map.Entry<Integer, Integer> entry : colorMapping.entrySet()) {
      colorResource =
          new ColorResource(
              entry.getKey(),
              context.getResources().getResourceEntryName(entry.getKey()),
              entry.getValue());
      if (!context
          .getResources()
          .getResourceTypeName(entry.getKey())
          .equals(RESOURCE_TYPE_NAME_COLOR)) {
        throw new IllegalArgumentException(
            "Non color resource found: name="
                + colorResource.name
                + ", typeId="
                + Integer.toHexString(colorResource.typeId & 0xFF));
      }
      PackageInfo packageInfo;
      if (colorResource.packageId == ANDROID_PACKAGE_ID) {
        packageInfo = ANDROID_PACKAGE_INFO;
      } else if (colorResource.packageId == APPLICATION_PACKAGE_ID) {
        packageInfo = applicationPackageInfo;
      } else {
        throw new IllegalArgumentException(
            "Not supported with unknown package id: " + colorResource.packageId);
      }
      if (!colorResourceMap.containsKey(packageInfo)) {
        colorResourceMap.put(packageInfo, new ArrayList<ColorResource>());
      }
      colorResourceMap.get(packageInfo).add(colorResource);

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Fix the mapping so every key is a genuine color resource (values/colors.xml entries, R.color.*).
  2. If resolving names dynamically with getIdentifier, verify defType is "color" before adding to the map.
  3. Remove or map-to-resource-ids entries that no longer reference colors after a refactor.

Example fix

// before
val overrides = mapOf(R.string.brand_color to R.color.new_color) // wrong type, throws

// after
val overrides = mapOf(R.color.brand_color to R.color.new_color)
Defensive patterns

Strategy: validation

Validate before calling

fun Map<Int, Int>.filterColorResources(context: Context): Map<Int, Int> =
    filterKeys { id ->
      context.resources.getResourceTypeName(id) == "color"
    }

Prevention

When it happens

Trigger: Passing a non-color resource ID in the colorOverride map, e.g. R.string.primary or R.dimen.spacing, instead of R.color.primary; building the map from generic resource keys parsed from config; ID collisions after refactoring a resource from color to drawable.

Common situations: Server-driven theming where keys are resource names resolved with getIdentifier and mis-typed; refactors that changed a color resource into a drawable (e.g. color -> gradient) without updating the override map.

Related errors


AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14). Data as JSON: /api/errors/7953fec56202ecd3. Report an issue: GitHub.