{"record":{"id":"40cc3f49b6336e11","repo":"material-components/material-components-android","slug":"no-color-resources-found-for-harmonization","errorCode":null,"errorMessage":"No color resources found for harmonization.","messagePattern":"No color resources found for harmonization\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/color/ColorResourcesTableCreator.java","lineNumber":112,"sourceCode":"      if (colorResource.packageId == ANDROID_PACKAGE_ID) {\n        packageInfo = ANDROID_PACKAGE_INFO;\n      } else if (colorResource.packageId == APPLICATION_PACKAGE_ID) {\n        packageInfo = applicationPackageInfo;\n      } else {\n        throw new IllegalArgumentException(\n            \"Not supported with unknown package id: \" + colorResource.packageId);\n      }\n      if (!colorResourceMap.containsKey(packageInfo)) {\n        colorResourceMap.put(packageInfo, new ArrayList<ColorResource>());\n      }\n      colorResourceMap.get(packageInfo).add(colorResource);\n    }\n    // Resource Type Ids are assigned by aapt arbitrarily, for each new type the next available\n    // number is assigned and used. The type id will be the same for resources that are the same\n    // type.\n    typeIdColor = colorResource.typeId;\n    if (typeIdColor == 0) {\n      throw new IllegalArgumentException(\"No color resources found for harmonization.\");\n    }\n    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\n    new ResTable(colorResourceMap).writeTo(outputStream);\n    return outputStream.toByteArray();\n  }\n\n  /**\n   * A Table chunk contains: a set of Packages, where a Package is a collection of Resources and a\n   * set of strings used by the Resources contained in those Packages.\n   *\n   * <p>The set of strings are contained in a StringPool chunk. Each Package is contained in a\n   * corresponding Package chunk. The StringPool chunk immediately follows the Table chunk header.\n   * The Package chunks follow the StringPool chunk.\n   */\n  private static class ResTable {\n    private static final short HEADER_SIZE = 0x000C;\n\n    private final ResChunkHeader header;","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/color/ColorResourcesTableCreator.java#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify with adb/shell that the involved color resources resolve normally (aapt dump resources).","Ensure no resource-modification framework (hot-patch, resource shrinker bug) is mangling type ids; disable it for the affected build.","Update to the latest Material Components version; report the case with the exact resource ids if reproducible."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// No caller-side pre-check exists (type id is resolved internally).\n// Guard the whole harmonization step so theming still applies without overrides:\nfun applyDynamicColorsSafely(activity: Activity, overrides: Map<Int, Int>) {\n  try {\n    DynamicColors.applyToActivityIfAvailable(activity)\n    if (overrides.isNotEmpty()) ColorResourcesTableCreator.create(activity, overrides)\n  } catch (e: IllegalArgumentException) {\n    // skip runtime color overrides; keep default theme\n  }\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) specifically around ColorResourcesTableCreator.create; treat as non-fatal theming degradation and fall back to static theme colors.","preventionTips":["Keep only validated color ids in the mapping (prevents upstream states that lead here).","Avoid resource-hotpatch frameworks in builds that use runtime color harmonization.","Pin a recent Material Components version and test on the target OEM runtimes."],"tags":["android","material-components","dynamic-color","resources","internal"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}