Hello. I have this class: <https://gist.github.com...
# serialization
m
Hello. I have this class: https://gist.github.com/mel4tonin4/a8255ea412dd3f5787deefac27afce4a It's compiled just fine in Android Studio, as part of the Android application project, but when I compile it in IDEA, as part of the supporting service project, it fails with the error "@Serializable annotation is ignored because it is impossible to serialize automatically interfaces or enums. Provide serializer manually via e.g.companion object" for both the object's. In both cases I'm using
kotlinx_serialization_runtime_version=0.14.0
In both cases the serialization plugin is selected with
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
in the top level build.gradle file where
kotlin_version=1.3.71
This is the build.gradle of the module that contains the class above: https://gist.github.com/mel4tonin4/9bf05d82f8901613b131998162250495 What's the reason for this difference?
t
Possible root cause: •
Terminated
must be sealed •
Terminated
must have
@Serializable
annotation
m
The
Started
object causes an error, too, but it's not derived by
Terminated
. In any case, why doesn't that happen when I build in Android Studio?
I just tryed, removing the class Terminated doesn't fix the issue.
t
You need runtime
0.20.0
Android Studio plugin include this version and it works
You use incompatible version. Kotlin
1.3.70
require runtime
0.20.0
💯 1
m
Thanks, Victor! I found the same document few hours ago. I already updated my code. Currently the Android application builds and runs. The supporting service builds but fails at runtime with: "Exception in thread "main" java.lang.NoSuchMethodError: 'void kotlinx.serialization.internal.SerialClassDescImpl.<init>(java.lang.String, kotlinx.serialization.internal.GeneratedSerializer)'"
I still don't understand why these differences emerged today with serialization. I never had problems on both platforms.
t
Do you use
_SerialClassDescImpl_
in your code?
Possibly you have dependencies, which use previous serialization runtime
👍 1
m
I'll check that. Thanks for the suggestion, Victor!
This is the list of the the jar files in the classpath of my supporting service application: https://gist.github.com/mel4tonin4/2ae736602b8b999f5406350c4c285370 The kotlinx-serialization is at line 159. It's version 0.20.0 and there are no other version of that jar. Moreover, this is the exception with stack trace: https://gist.github.com/mel4tonin4/7376c34a9c54f0c4f2aa594dda872ad1 As you can see the exception is thrown while running deserialization code generated for my own classes. The application is trying to de-serialize its configuration file.
Also, querying a classloader for the URL for the class
SerialClassDescImpl
at runtime, gives, correctly: jarfile/[...]/service/jars/kotlinx-serialization-runtime-0.20.0.jar!/kotlinx/serialization/internal/SerialClassDescImpl.class
t
Class is internal since
0.20.0
m
It's used in the generated code, not in mine. Is the generated code allowed to use it? Does it mean that an older compiler is being called to generate the serializers?
The plugin version is selected in the top level guild.gradle file with:
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
where
kotlin_version=1.3.71
.
In fact, if I apply
Copy code
plugins { 
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.71'
}
in the offending module, I get: Error resolving plugin [id: 'org.jetbrains.kotlin.plugin.serialization', version: '1.3.71']
Plugin request for plugin already on the classpath must not include a version
And using
1.3.70
, just in case, doesn't change anything.
As described in https://github.com/Kotlin/kotlinx.serialization/issues/736#issuecomment-600485633 my buildSrc/build.gradle was outdated and loaded the plugin before anything else, so it set the plugin version.
Now the problem with my code is fixed. The problems are with ktor.
Thanks for helping me, @turansky!
👍 1
Updating ktor to 1.3.2 fixed the problem with ktor-serialization, too.
t
Sync required for all depencies Different Kotlin versions - typical problem for serialization