【问题标题】:java.lang.NoSuchMethodError startRestartGroup after upgrading Jetpack Compose to 1.0.0‑beta07将 Jetpack Compose 升级到 1.0.0-beta07 后的 java.lang.NoSuchMethodError startRestartGroup
【发布时间】:2021-05-24 05:33:43
【问题描述】:

我刚刚将 compose 版本更新为 1.0.0-beta07,并显示此运行时错误

No interface method startRestartGroup(ILjava/lang/String;)Landroidx/compose/runtime/Composer; in class Landroidx/compose/runtime/Composer; or its super classes (declaration of 'androidx.compose.runtime.Composer' 
....
 at com.google.accompanist.coil.CoilImage__CoilKt.CoilImage(Coil.kt:245)
        at com.google.accompanist.coil.CoilImage.CoilImage(Coil.kt:1)

下面是我的 gradle 依赖文件

implementation 'androidx.core:core-ktx:1.5.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'

    implementation "androidx.compose.compiler:compiler:$compose_version"
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation "androidx.compose.runtime:runtime:$compose_version"
    implementation "androidx.compose.runtime:runtime-livedata:$compose_version"

    implementation 'androidx.activity:activity-compose:1.3.0-alpha08'
    implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'

    implementation "io.coil-kt:coil-gif:1.2.1"
    implementation "io.coil-kt:coil-svg:1.2.1"
    implementation "com.google.accompanist:accompanist-coil:0.6.2"

和版本compose_version = '1.0.0-beta07'

【问题讨论】:

    标签: android android-jetpack-compose


    【解决方案1】:

    每个库都需要针对beta07 重新编译才能工作,根据Compose release notes:

    注意:依赖于 Compose 的库需要使用 1.0.0-beta07 版本重新编译。否则,库可能会遇到NoSuchMethodError,例如: java.lang.NoSuchMethodError: No interface method startReplaceableGroup(ILjava/lang/String;)V in class Landroidx/compose/runtime/Composer; or its super classes. (Ia34e6)

    在您的情况下,您必须使用 0.10.0 更新伴奏库。

    变化:

    implementation "com.google.accompanist:accompanist-coil:0.6.2"
    

    到

    implementation "com.google.accompanist:accompanist-coil:0.10.0"
    

    【讨论】:

    • CoilImage 不再存在,而是使用带有新画家 rememberCoilPainter 的 Image。例如Image(painter = rememberCoilPainter(imageUrl))
    • 好答案,最新版本:实施“com.google.accompanist:accompanist-coil:0.11.0”
    【解决方案2】:

    Coil、Glide 和 Image Loading Core 已被移除 在 v0.14.0 中被弃用后,是时候删除线圈、滑翔和图像加载核心库了。可以在 Kotlin Slack 上看到一些关于此的讨论:https://kotlinlang.slack.com/archives/CJLTWPH7S/p1627482619344000。建议转至https://coil-kt.github.io/coil/compose/

    所以改变;

    implementation "com.google.accompanist:accompanist-coil:0.6.2"
    

    到

    implementation("io.coil-kt:coil-compose:1.3.2")
    

    还有; CoilImage 也去掉了,可以用了;

    Image(
        painter = rememberImagePainter("https://www.example.com/image.jpg"),
        contentDescription = null,
        modifier = Modifier.size(128.dp)
    )
    

    【讨论】:

      【解决方案3】:

      确保您所有的撰写库都使用相同的版本1.0.0-beta07。这应该可以解决您的问题。

      【讨论】:

        猜你喜欢
        • 2021-08-09
        • 1970-01-01
        • 1970-01-01
        • 2021-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-29
        相关资源
        最近更新 更多