NoSuchMethodError on Android
tiago-carvalho-deltatre opened this issue · comments
I'm getting this error when running on my android compose multiplatform app (Android and iOS support)
java.lang.NoSuchMethodError: No static method readResourceBytes(Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; in class Lorg/jetbrains/compose/resources/ResourceReader_androidKt; or its super classes (declaration of 'org.jetbrains.compose.resources.ResourceReader_androidKt' appears in /data/app/~~2kUBRrt_cmjg-QaHysMpvA==/pt.tiagocarvalho.truelevelpadel-FI-IpVVTTjPgw6LcLnqYNQ==/base.apk!classes20.dex)
kotlin = "2.0.0-RC3"
coil = "3.0.0-alpha06"
compose = "1.6.7"
compose-plugin = "1.6.10-rc01"
kottie = "1.8.3"
val composition = rememberKottieComposition(
spec = KottieCompositionSpec.File("files/celebrate.json"),
)
val animationState by animateKottieCompositionAsState(
composition = composition,
iterations = 1,
)
Managed to get it to work with:
var compositionSpec by remember { mutableStateOf<KottieCompositionSpec?>(null) }
LaunchedEffect("spec") {
val jsonFile = Res.readBytes("files/celebrate.json").decodeToString()
compositionSpec = KottieCompositionSpec.JsonString(jsonFile)
}
val composition = compositionSpec?.let {
rememberKottieComposition(
spec = it,
)
}
thanks @tiago-carvalho-deltatre, I've fixed it and released a new version 1.8.5. You can use KottieCompositionSpec.File("files/celebrate.json")
@ismai117 I'm seeing the same problem on Desktop (Multiplatform) and I'm already on 1.8.5 which doesn't help.
Kotlin: 1.9.24
Compose Multiplatform: 1.6.10
@ismai117 I'm seeing the same problem on Desktop (Multiplatform) and I'm already on 1.8.5 which doesn't help.
Kotlin: 1.9.24 Compose Multiplatform: 1.6.10
In Compose 1.6.10, JetBrains has changed the readResourceBytes method signature.
need to recompile with the latest version of Compose.
I've released a new version 1.8.6. Res.readBytes has been removed from the library module so you now have the option to do it yourself.
var animation by remember { mutableStateOf("") }
LaunchedEffect(Unit){
animation = Res.readBytes("files/animation.json").decodeToString()
}
val composition = rememberKottieComposition(
spec = KottieCompositionSpec.File(animation) // Or KottieCompositionSpec.Url || KottieCompositionSpec.JsonString
)