Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose preview stopped working in Arctic Fox with Patch 1

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

like image 332
Primož Ivančič Avatar asked Aug 19 '21 10:08

Primož Ivančič


People also ask

What is the latest version of jetpack compose?

Today, we're releasing version 1.2 of Jetpack Compose, Android's modern, native UI toolkit, continuing to build out our roadmap.

What is LazyColumn in jetpack compose?

A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.

What is mutableStateOf jetpack compose?

mutableStateOf creates an observable MutableState<T> , which is an observable type integrated with the compose runtime. Any changes to value will schedule recomposition of any composable functions that read value . In the case of ExpandingCard , whenever expanded changes, it causes ExpandingCard to be recomposed.

How do you add paddings in jetpack?

To set padding for Text composable, in Android Jetpack Compose, assign modifier parameter of Text with Modifier companion object, where padding() method is called on the Modifier. Pass required padding value in the padding() function call. The following is a sample code snippet to set the padding for Text composable.

How to use jetpack compose preview in Android Studio?

In Jetpack Compose we can see the preview of our code in Android studio. It allows us to see the output without running our app. Click the split to see both code and preview. How to add a preview? You need to add @Preview () annotation before the composable function. After adding this annotation we are able to see the preview of our UI.

What's new in Android Studio Arctic fox?

Up until now, Android Studio Arctic Fox was in the beta release channel for Android Studio. During its time in development, Google added new features like Accessibility Scanner, Test Matrix, native support for M1 Macs, and full support for Jetpack Compose. On top of the usual bug fixes, Arctic Fox also changes Android Studio’s versioning scheme.

What is the latest version of Arctic fox?

Instead of version 4.3, Arctic Fox is version 2020.3.1. This new versioning is so Android Studio’s versions match the versions of IntelliJ IDEA that they’re based on.

How does jetpack compose differ from flutter?

Google says that Jetpack Compose is a toolkit for building "native UI". But how come it's a native UI? Compose it's a library that not present natively on Android devices, and must be included in each app that uses it. So what differs it from Flutter. I would be glad if you could answer. Thank you.


Video Answer


1 Answers

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)
    }
like image 96
Damiancioo Avatar answered Oct 08 '22 14:10

Damiancioo