[SOLVED] (Jetpack Compose) Modifier unresolved reference: size

I’m working through the Basic layouts in Compose codelab and I’ve hit an error I can’t figure out – in trying to implement Modifier.size(88.dp) I’m encountering an “unresolved reference” error.

I understand that this error generally means I’m trying to invoke a method or property that doesn’t exist, but it should – size() is a documented method for Modifier in Compose. As far as I can tell I’m importing the correct Modifier as well (androidx.compose.ui.Modifier). The code copied and pasted directly from the codelab also has this same error so unless the codelab is using incorrect syntax …

Can anyone help? Relevant code below:

import androidx.compose.ui.Modifier

/* ... */

@Composable
fun AlignYourBodyElement(
    modifier: Modifier = Modifier
) {
    // Implement composable here
    Column(
        modifier = modifier,
    ) {
        Image(
            painter = painterResource(R.drawable.ab1_inversions),
            contentDescription = null,
            contentScale = ContentScale.Crop,
            modifier = Modifier
                .size(88.dp) // error is here
                .clip(CircleShape),
        )
        Text(
            text = stringResource(R.string.ab1_inversions),
        )
    }
}
1 Like

Had to import the size function explicitly:

import androidx.compose.foundation.layout.size

Android Studio didn’t offer an import for this, just “rename,” but once I added it to the project manually, it worked.

1 Like