Jetpack Compose preview stopped working in Arctic Fox with Patch 1
S

6

20

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).

Scree answered 19/8, 2021 at 10:8 Comment(6)
I have similar problem - in my case compose has problem with fetching dimensionResource(id = R.dimen.some_value) in preview + I'm using preview 2Maryettamaryjane
Is this the issue in the main module? Any module? Dynamic feature module?Seoul
Yes I have this problem only in dynamic featureMaryettamaryjane
I have the same issue. Image( painter = painterResource(id = R.drawable.flower4) ) is not workingPhilanthropist
I have same issue with color resources.(dynamic module refers app module resource)Aaren
I have this issue in non-dynamic module, but when the string resource is in another moduleDrupelet
S
6

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.

Edit 2 (copied from comments - Feb 2024): It apparently got broken again in Giraffe and Hedgehog.

Scree answered 19/8, 2021 at 11:53 Comment(3)
maybe but it is present in Android Studio Electric Eel | 2022.1.1 Patch 1 or very similar issue where you need to refresh manually preview again after each change for this error to dissapear.Fescennine
Fixed in Android Studio Flamingo | 2022.2.1 Beta 4Atomics
Well, seems to be broken again on Giraffe and Hedgehog...Namaqualand
S
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)
    }
Spermatophyte answered 6/1, 2022 at 11:12 Comment(0)
C
0

For me it starts working after run the application on a simulator (2022.1.1)

Cofer answered 12/4, 2023 at 17:22 Comment(0)
R
0

In my case I got to solve the issue by using

implementation(platform("androidx.compose:compose-bom:2023.08.00"))

instead of

implementation(platform("androidx.compose:compose-bom:2024.02.02"))

Android Studio HedgeHog 2023.1.1 Patch 2

Rawson answered 13/3, 2024 at 23:35 Comment(0)
H
0

Was using it fine just yesterday and today it broke but only for a screen, fixed it by setting the api level parameter of the preview annotation as was stated in the layout fidelity warning ("The current rendering only supports APIs up to 33").

Heliotropism answered 10/5, 2024 at 17:31 Comment(0)
I
-1

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"
}
Idou answered 8/11, 2021 at 18:38 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.