diff --git a/lib/java/com/google/android/material/color/ColorResourcesTableCreator.java b/lib/java/com/google/android/material/color/ColorResourcesTableCreator.java index cabc900189b..13a05ea8048 100644 --- a/lib/java/com/google/android/material/color/ColorResourcesTableCreator.java +++ b/lib/java/com/google/android/material/color/ColorResourcesTableCreator.java @@ -338,16 +338,38 @@ private static class PackageChunk { PackageChunk(PackageInfo packageInfo, List colorResources) { this.packageInfo = packageInfo; - // Placeholder String type, since only XML color resources will be replaced at runtime. - typeStrings = new StringPoolChunk(false, "?1", "?2", "?3", "?4", "?5", "color"); + typeStrings = new StringPoolChunk(false, generateTypeStrings(colorResources)); + keyStrings = new StringPoolChunk(true, generateKeyStrings(colorResources)); + typeSpecChunk = new TypeSpecChunk(colorResources); + + header = new ResChunkHeader(HEADER_TYPE_PACKAGE, HEADER_SIZE, getChunkSize()); + } + + private String[] generateTypeStrings(List colorResources) { + if (!colorResources.isEmpty()) { + byte colorTypeId = colorResources.get(0).typeId; + String[] types = new String[colorTypeId]; + + // Placeholder String type, since only XML color resources will be replaced at runtime. + for (int i = 0; i < colorTypeId - 1; i++) { + types[i] = "?" + (i + 1); + } + + types[colorTypeId - 1] = "color"; + + return types; + } else { + return new String[0]; + } + } + + private String[] generateKeyStrings(List colorResources) { String[] keys = new String[colorResources.size()]; for (int i = 0; i < colorResources.size(); i++) { keys[i] = colorResources.get(i).name; } - keyStrings = new StringPoolChunk(true, keys); - typeSpecChunk = new TypeSpecChunk(colorResources); - header = new ResChunkHeader(HEADER_TYPE_PACKAGE, HEADER_SIZE, getChunkSize()); + return keys; } void writeTo(ByteArrayOutputStream outputStream) throws IOException {