androidandroid-jetpack-composeandroid-jetpack-compose-previewandroid-jetpack-compose-modifier

Preview java.lang.NoSuchMethodError: androidx.compose.foundation.layout.SizeKt.fillMaxWidth$default


I started migrate our code to Compose and have problem with @Preview. For example, when I use modifier.fillMaxWidth() without default param "fraction = 1f" I have render problem

java.lang.NoSuchMethodError: 'androidx.compose.ui.Modifier androidx.compose.foundation.layout.SizeKt.fillMaxWidth$default(androidx.compose.ui.Modifier, java.lang.Float, int, java.lang.Object)'

or use padding without bottom param

.padding(
    top = dimensionResource(id = R.dimen._4sdp),
    start = dimensionResource(id = R.dimen._16sdp),
    end = dimensionResource(id = R.dimen._16sdp)
)

java.lang.NoSuchMethodError: 'androidx.compose.ui.Modifier androidx.compose.foundation.layout.PaddingKt.padding-qDBjuR0$default(androidx.compose.ui.Modifier, androidx.compose.ui.unit.Dp, androidx.compose.ui.unit.Dp, androidx.compose.ui.unit.Dp, androidx.compose.ui.unit.Dp, int, java.lang.Object)'

here the code I use

@Composable
fun Info(
    modifier: Modifier = Modifier,
    step: String,
    stepInfo: String,
) {
    Column(modifier = modifier.fillMaxWidth(fraction = 1f)) {
        Text(
            text = step,
            modifier = Modifier
                .background(
                    color = colorResource(id = R.color.color_on_background_variant3),
                    shape = RoundedCornerShape(90)
                )
                .size(dimensionResource(id = R.dimen._28sdp))
                .padding(dimensionResource(id = R.dimen._6sdp))
                .align(Alignment.CenterHorizontally),
            textAlign = TextAlign.Center
        )
        Text(
            text = stepInfo,
            textAlign = TextAlign.Center,
            modifier = Modifier
                .padding(
                    top = dimensionResource(id = R.dimen._4sdp),
                    start = dimensionResource(id = R.dimen._16sdp),
                    end = dimensionResource(id = R.dimen._16sdp),
                    bottom = 0.dp
                )
                .align(Alignment.CenterHorizontally),
        )
    }
}

@Preview
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "InfoPreviewNight")
@Composable
fun InfoPreview() {
    MdcTheme {
        Info(
            step = "1",
            stepInfo = ".............."
        )
    }
}

buidld.gradle (:app)

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-parcelize'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'com.google.firebase.appdistribution'
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.3.1'
    }
    dependencies {
        implementation platform('androidx.compose:compose-bom:2022.10.00')
        implementation "androidx.compose.runtime:runtime"
        implementation "androidx.compose.ui:ui"
        implementation "androidx.compose.foundation:foundation"
        implementation "androidx.compose.foundation:foundation-layout"
        implementation "androidx.compose.material:material"
        implementation "androidx.compose.runtime:runtime-livedata"
        implementation "androidx.compose.ui:ui-tooling-preview"
        implementation "com.google.accompanist:accompanist-themeadapter-material:0.30.1"
        debugImplementation "androidx.compose.ui:ui-tooling"
        androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    }

Gradle Plugin Version ------ 7.2.2 Gradle Version ------- 7.3.3

I tried change kotlinCompilerExtensionVersion but I got no result and stackoverflow question didn't helped.


Solution

  • After updating Android Studio to Giraffe | 2022.3.1 Patch 1 version, the broblem has gone