Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Color] Failed to create the ColorResourcesTableCreator. #4472

Open
brahmkshatriya opened this issue Dec 15, 2024 · 1 comment
Open

[Color] Failed to create the ColorResourcesTableCreator. #4472

brahmkshatriya opened this issue Dec 15, 2024 · 1 comment

Comments

@brahmkshatriya
Copy link

brahmkshatriya commented Dec 15, 2024

Description: Applying DynamicColors 2nd time, generates error after recreating the activity. The color does not get applied.

Failed to create the ColorResourcesTableCreator. 
 java.lang.IllegalArgumentException: Non color resource found: name=com.example.dynamiccolortest:?5/com.example.dynamiccolortest:color/material_personalized_color_on_secondary, typeId=5
  at com.google.android.material.color.ColorResourcesTableCreator.create(ColorResourcesTableCreator.java:90)
  at com.google.android.material.color.ColorResourcesLoaderCreator.create(ColorResourcesLoaderCreator.java:46)
  at com.google.android.material.color.ResourcesLoaderUtils.addResourcesLoaderToContext(ResourcesLoaderUtils.java:35)
  at com.google.android.material.color.ResourcesLoaderColorResourcesOverride.applyIfPossible(ResourcesLoaderColorResourcesOverride.java:49)
  at com.google.android.material.color.DynamicColors.applyToActivityIfAvailable(DynamicColors.java:310)
  at com.google.android.material.color.DynamicColors$DynamicColorsActivityLifecycleCallbacks.onActivityPreCreated(DynamicColors.java:451)
  at android.app.Application.dispatchActivityPreCreated(Application.java:356)
  at android.app.Activity.dispatchActivityPreCreated(Activity.java:1505)
  at android.app.Activity.performCreate(Activity.java:8947)
  at android.app.Activity.performCreate(Activity.java:8938)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1536)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3975)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4173)
  at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:6242)
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:6133)
  at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:80)
  at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:60)
  at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:231)
  at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:152)
  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:93)
  at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:70)
  at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:6199)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2605)
  at android.os.Handler.dispatchMessage(Handler.java:107)
  at android.os.Looper.loopOnce(Looper.java:232)
  at android.os.Looper.loop(Looper.java:317)
  at android.app.ActivityThread.main(ActivityThread.java:8592)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:583)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

Expected behavior: Color gets applied.

Minimal Sample code:

class MainActivity : AppCompatActivity() {

    private val colors = listOf(Color.RED, Color.GREEN, Color.BLUE)
    private fun applyColor(){
        val color = colors.random()
        val options = DynamicColorsOptions.Builder()
            .setContentBasedSource(color)
            .build()
        DynamicColors.applyToActivitiesIfAvailable(application, options)
        recreate()
    }
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<Button>(R.id.button).setOnClickListener { applyColor() }
    }
}
@brahmkshatriya
Copy link
Author

I also got this error on my app

Failed to create the ColorResourcesTableCreator.
 java.lang.ArrayIndexOutOfBoundsException: src.length=132 srcPos=0 dst.length=135 dstPos=2 length=-124
  at java.lang.System.arraycopy(Native Method)
  at com.google.android.material.color.ColorResourcesTableCreator.stringToByteArrayUtf8(ColorResourcesTableCreator.java:616)
  at com.google.android.material.color.ColorResourcesTableCreator.access$800(ColorResourcesTableCreator.java:40)
  at com.google.android.material.color.ColorResourcesTableCreator$StringPoolChunk.processString(ColorResourcesTableCreator.java:299)
  at com.google.android.material.color.ColorResourcesTableCreator$StringPoolChunk.<init>(ColorResourcesTableCreator.java:223)
  at com.google.android.material.color.ColorResourcesTableCreator$PackageChunk.<init>(ColorResourcesTableCreator.java:347)
  at com.google.android.material.color.ColorResourcesTableCreator$ResTable.<init>(ColorResourcesTableCreator.java:140)
  at com.google.android.material.color.ColorResourcesTableCreator.create(ColorResourcesTableCreator.java:114)
  at com.google.android.material.color.ColorResourcesLoaderCreator.create(ColorResourcesLoaderCreator.java:46)
  at com.google.android.material.color.ResourcesLoaderUtils.addResourcesLoaderToContext(ResourcesLoaderUtils.java:35)
  at com.google.android.material.color.ResourcesLoaderColorResourcesOverride.applyIfPossible(ResourcesLoaderColorResourcesOverride.java:49)
  at com.google.android.material.color.DynamicColors.applyToActivityIfAvailable(DynamicColors.java:310)
  at com.google.android.material.color.DynamicColors$DynamicColorsActivityLifecycleCallbacks.onActivityPreCreated(DynamicColors.java:451)
  at android.app.Application.dispatchActivityPreCreated(Application.java:356)
  at android.app.Activity.dispatchActivityPreCreated(Activity.java:1505)
  at android.app.Activity.performCreate(Activity.java:8947)
  at android.app.Activity.performCreate(Activity.java:8938)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1536)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3975)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4173)
  at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:6242)
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:6133)
  at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:80)
  at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:60)
  at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:231)
  at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:152)
  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:93)
  at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:70)
  at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:6199)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2605)
  at android.os.Handler.dispatchMessage(Handler.java:107)
  at android.os.Looper.loopOnce(Looper.java:232)
  at android.os.Looper.loop(Looper.java:317)
  at android.app.ActivityThread.main(ActivityThread.java:8592)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:583)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants