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

No color resources found for harmonization.

Error message

No color resources found for harmonization.

What it means

After processing the mapping, the creator records the type id of the last color resource; if it is 0 the loop produced no usable color entries and the method throws 'No color resources found for harmonization.' instead of writing an empty/invalid table. It is effectively a final sanity check complementing the empty-map check.

Source

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

      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);
    }
    // Resource Type Ids are assigned by aapt arbitrarily, for each new type the next available
    // number is assigned and used. The type id will be the same for resources that are the same
    // type.
    typeIdColor = colorResource.typeId;
    if (typeIdColor == 0) {
      throw new IllegalArgumentException("No color resources found for harmonization.");
    }
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    new ResTable(colorResourceMap).writeTo(outputStream);
    return outputStream.toByteArray();
  }

  /**
   * A Table chunk contains: a set of Packages, where a Package is a collection of Resources and a
   * set of strings used by the Resources contained in those Packages.
   *
   * <p>The set of strings are contained in a StringPool chunk. Each Package is contained in a
   * corresponding Package chunk. The StringPool chunk immediately follows the Table chunk header.
   * The Package chunks follow the StringPool chunk.
   */
  private static class ResTable {
    private static final short HEADER_SIZE = 0x000C;

    private final ResChunkHeader header;

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Verify with adb/shell that the involved color resources resolve normally (aapt dump resources).
  2. Ensure no resource-modification framework (hot-patch, resource shrinker bug) is mangling type ids; disable it for the affected build.
  3. Update to the latest Material Components version; report the case with the exact resource ids if reproducible.
Defensive patterns

Strategy: fallback

Validate before calling

// No caller-side pre-check exists (type id is resolved internally).
// Guard the whole harmonization step so theming still applies without overrides:
fun applyDynamicColorsSafely(activity: Activity, overrides: Map<Int, Int>) {
  try {
    DynamicColors.applyToActivityIfAvailable(activity)
    if (overrides.isNotEmpty()) ColorResourcesTableCreator.create(activity, overrides)
  } catch (e: IllegalArgumentException) {
    // skip runtime color overrides; keep default theme
  }
}

Try / catch

catch (IllegalArgumentException e) specifically around ColorResourcesTableCreator.create; treat as non-fatal theming degradation and fall back to static theme colors.

Prevention

When it happens

Trigger: Reaching create() with a mapping whose entries do not yield a valid color type id (edge runtime behavior after earlier validations passed); future refactors where the map is mutated to only non-standard entries.

Common situations: Rare in practice; surfaces on exotic runtimes or when resource tables are modified (resource-canary / hotfix frameworks) so getResourceTypeName works but type ids resolve to 0.

Related errors


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