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

Not supported with unknown package id: {packageId}

Error message

Not supported with unknown package id: {packageId}

What it means

Each color resource's package ID must be either 0x01 (the android framework package) or the application package ID (0x7f by default) for the generated resources table to be well-formed. Any other package id throws IllegalArgumentException, because the table writer has no package chunk to represent it.

Source

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

              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);
    }
    // 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();
  }

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Only pass application (R.color.*) or android (android.R.color.*) color ids in the mapping.
  2. Ensure the Context passed to create() is the application context that owns the resources in the map.
  3. Copy cross-package colors into your own res/colors before mapping them.

Example fix

// before (otherAppResources resolves to a foreign package id)
val overrides = mapOf(otherAppResources.getIdentifier("brand" ,"color", "com.other") to newColor)
ColorResourcesTableCreator.create(context, overrides) // throws

// after
colors.xml: <color name="brand">#FF00FF</color>
val overrides = mapOf(R.color.brand to newColor)
Defensive patterns

Strategy: validation

Validate before calling

fun isSupportedPackageId(id: Int): Boolean {
  val packageId = (id ushr 24) and 0xFF
  return packageId == 0x01 || packageId == 0x7f
}

val safeMap = colorMapping.filterKeys { isSupportedPackageId(it) }

Prevention

When it happens

Trigger: Passing a color resource ID belonging to a dynamic feature module, an AAR with a non-standard package id, or an R class from another app/context (e.g. resolving colors from a different application's Resources); runtimes that assign custom package ids to shared libraries.

Common situations: Multi-module apps mixing R constants from feature modules resolved through a different Context; device builds with non-standard resource package ids (some OEM/shared-library configurations); using resources obtained from another package's context in the harmonization map.

Related errors


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