skip to Main Content

With the first patch for AS Arctic Fox Jetpack Compose previews stopped working.

I’m getting this error for all previews – even older ones, which worked fine a while back:

android.content.res.Resources$NotFoundException: Could not resolve resource value: [some hex value]

Are here any quick fixes for this? Clearing caches and the usual stuff did not work.

EDIT:
Looks like the problem is not always present. Some preview started working, while other are still failing.

EDIT 2:
This is happening in dynamic feature modules, when there’s a need for resources from the main module or painterResource() is being used (even is resource from the same module is to be displayed).

4

Answers


  1. Chosen as BEST ANSWER

    This got fixed in AS Bumblebee, patch 2.

    Edit (copied from comments): It then got broken again in Electric Eel | 2022.1.1 and fixed again in Flamingo | 2022.2.1 Beta 4.


  2. As a temporary hack workaround I did this to get past the error and preview the UI elements.

    //import androidx.compose.ui.res.stringResource
    
    fun stringResource(id: Int): String {
        when (id) {
            R.string.res_id -> return "Foo"
            ...
        }
        return "missing res_id"
    }
    
    Login or Signup to reply.
  3. Same problem here with dynamic-modules project.
    Inspired by above answer, I’ve made another temporary workaround while waiting for Compose team to fix this.

    import androidx.compose.ui.res.stringResource as originalStringResource
    
    @Composable
    @ReadOnlyComposable
    fun stringResourceSafe(@StringRes id: Int): String =
        if (BuildConfig.DEBUG) {
            val resources = LocalContext.current.resources
            try {
                resources.getString(id)
            } catch (e: Resources.NotFoundException) {
                "missing res."
            }
        } else {
            originalStringResource(id)
        }
    
    Login or Signup to reply.
  4. For me it starts working after run the application on a simulator (2022.1.1)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search