ProGuard optimization causes "java.lang.VerifyError: Bad type on operand stack"
Describe the bug
If I try to optimize the application by disabling
# -dontoptimize
I get the following error:
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
dev/mikchan/misc/ksp/model/Model$$serializer.<clinit>()V @38: putstatic
Reason:
Type 'dev/mikchan/misc/ksp/shadow/kotlinx/serialization/descriptors/SerialDescriptor' (current frame, stack[0]) is not assignable to 'dev/mikchan/misc/ksp/shadow/kotlinx/serialization/internal/PluginGeneratedSerialDescriptor'
Current Frame:
bci: @38
flags: { }
locals: { 'dev/mikchan/misc/ksp/shadow/kotlinx/serialization/internal/PluginGeneratedSerialDescriptor' }
stack: { 'dev/mikchan/misc/ksp/shadow/kotlinx/serialization/descriptors/SerialDescriptor' }
Bytecode:
0000000: bb00 0759 b700 18b3 0014 bb00 1059 1202
0000010: b200 14c0 000f 04b7 001b 594b 1203 03b6
0000020: 001c 2ac0 000c b300 15b1
at dev.mikchan.misc.ksp.model.Model$Companion.serializer(Model.kt:5)
at dev.mikchan.misc.ksp.MainKt.main(Main.kt:1014)
Process finished with exit code 1
If I disable the optimization, though, everything works OK.
To Reproduce
Here's a project with reproduction: https://github.com/wtlgo/Kotlin-Serialization-Proguard
Expected behavior
It should work correctly either with or without optimization
Environment
- Kotlin version: 2.0.0
- Library version: 1.7.0
- Kotlin platforms: JVM
- Gradle version: 8.5
- IDE version (if bug is related to the IDE): It isn't related, but it's IntelliJ IDEA 2024.1.2 (Ultimate Edition)
- Other relevant context: Windows 10,
com.guardsquare:proguard-gradle:7.5.0
We have exactly the same issue in our project. Any updates on this?
Hi, we will try to investigate this problem soon
@buehlerjochen, @wtlgo try to add this rule to your ProGuard rules file
-keepclassmembers public class **$$serializer {
private ** descriptor;
}
Related issue in ProGuard https://github.com/Guardsquare/proguard/issues/415
@shanshin Sorry for the late response, Just tested you proposal and it seems to solve the issue. Thank you very much!
Yeah, works for me too. Thank you! I'm going to remove my reproduction repo, here's a zip of it for archive purposes.