material-components / material-components/material-components-android

[Color] HarmonizedColors#applyToContextIfAvailable sometimes crashes on Samsung devices running Android 15

Open
#4,927 0 comments 0 reactions 1 assignee View on GitHub

@pekingme is already working on this.

Since Sep 11, 2025.

bug Feature: Color
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Version: **1.14.0-alpha04**

Exclusively on various Samsung devices running Android 15, I got many automated crash reports triggered by `HarmonizedColors#applyToContextIfAvailable`:

```
Caused by: java.lang.IllegalArgumentException: Cannot modify resource loaders of ResourcesImpl not registered with ResourcesManager
at android.app.ResourcesManager$UpdateHandler.onLoadersChanged(ResourcesManager.java:2240)
at android.content.res.Resources.addLoaders(Resources.java:2692)
at com.google.android.material.color.ResourcesLoaderUtils.addResourcesLoaderToContext(ResourcesLoaderUtils.java:37)
at com.google.android.material.color.HarmonizedColors.applyToContextIfAvailable(HarmonizedColors.java:75)
```

It looks like this happen only when an Activity is recreated (for example on orientation change)

The `IllegalArgumentException` is thrown by the framework here:

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/android/app/ResourcesManager.java;drc=6d8e2819f0f3930d24b555f9f067d1880854ed19;l=1948

In fact the crash happens whenever `ResourcesLoaderUtils#addResourcesLoaderToContext` is called, thus this crash is also triggered if `ColorResourcesOverride#applyIfPossible` is called. There are probably other calls affected too.

So, I suppose Samsung screw something in its changes to theming or the system ?

On the app side, is there any other work-around than to guard these calls with a `try-catch` block catching `IllegalArgumentException` ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.