@sandwwraith As discussed in issue #72 I am having issues with the kotlinx serialization plugin that generates the serializers for models that make use of generics. This is the sample project I am working on that reproduces the problem: https://github.com/nico-gonzalez/K-Places/tree/kotlinx-serialization. The url points to kotlinx-serialization branch which is the one I am using to test this. My idea was to replace the usage of Gson with this by setting the kotlinx serialization dependency only on the data module as it was the case for Gson dependency
To reproduce this you just need to hit build and you will get the following sort of errors when :data:kaptDebugKotlin. Note that it seems that the plugin is set up and running and it is indeed generating the $serializer classes for the different models with @Serializable annotation. Let me know in case you need anything else from my side.
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/Response.java:75: error: non-static type variable T cannot be referenced from a static context
public static final class $serializer implements kotlinx.serialization.KSerializer<com.edreams.android.workshops.kotlin.data.venues.remote.response.Response<? extends T>> {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/Response.java:85: error: non-static type variable T cannot be referenced from a static context
com.edreams.android.workshops.kotlin.data.venues.remote.response.Response<? extends T> old) {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/Response.java:83: error: non-static type variable T cannot be referenced from a static context
public com.edreams.android.workshops.kotlin.data.venues.remote.response.Response<T> update(@org.jetbrains.annotations.NotNull()
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/Response.java:98: error: non-static type variable T cannot be referenced from a static context
com.edreams.android.workshops.kotlin.data.venues.remote.response.Response<? extends T> obj) {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/Response.java:103: error: non-static type variable T cannot be referenced from a static context
public com.edreams.android.workshops.kotlin.data.venues.remote.response.Response<T> load(@org.jetbrains.annotations.NotNull()
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/Response.java:109: error: cannot find symbol
kotlinx.serialization.KSerializer<T0> typeSerial0) {
^
symbol: class T0
location: class $serializer
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/FourSquareResponse.java:75: error: non-static type variable T cannot be referenced from a static context
public static final class $serializer implements kotlinx.serialization.KSerializer<com.edreams.android.workshops.kotlin.data.venues.remote.response.FourSquareResponse<? extends T>> {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/FourSquareResponse.java:85: error: non-static type variable T cannot be referenced from a static context
com.edreams.android.workshops.kotlin.data.venues.remote.response.FourSquareResponse<? extends T> old) {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/FourSquareResponse.java:83: error: non-static type variable T cannot be referenced from a static context
public com.edreams.android.workshops.kotlin.data.venues.remote.response.FourSquareResponse<T> update(@org.jetbrains.annotations.NotNull()
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/FourSquareResponse.java:98: error: non-static type variable T cannot be referenced from a static context
com.edreams.android.workshops.kotlin.data.venues.remote.response.FourSquareResponse<? extends T> obj) {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/FourSquareResponse.java:103: error: non-static type variable T cannot be referenced from a static context
public com.edreams.android.workshops.kotlin.data.venues.remote.response.FourSquareResponse<T> load(@org.jetbrains.annotations.NotNull()
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/FourSquareResponse.java:109: error: cannot find symbol
kotlinx.serialization.KSerializer<T0> typeSerial0) {
^
symbol: class T0
location: class $serializer
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/GroupsResponse.java:75: error: non-static type variable T cannot be referenced from a static context
public static final class $serializer implements kotlinx.serialization.KSerializer<com.edreams.android.workshops.kotlin.data.venues.remote.response.GroupsResponse<? extends T>> {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/GroupsResponse.java:85: error: non-static type variable T cannot be referenced from a static context
com.edreams.android.workshops.kotlin.data.venues.remote.response.GroupsResponse<? extends T> old) {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/GroupsResponse.java:83: error: non-static type variable T cannot be referenced from a static context
public com.edreams.android.workshops.kotlin.data.venues.remote.response.GroupsResponse<T> update(@org.jetbrains.annotations.NotNull()
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/GroupsResponse.java:98: error: non-static type variable T cannot be referenced from a static context
com.edreams.android.workshops.kotlin.data.venues.remote.response.GroupsResponse<? extends T> obj) {
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/GroupsResponse.java:103: error: non-static type variable T cannot be referenced from a static context
public com.edreams.android.workshops.kotlin.data.venues.remote.response.GroupsResponse<T> load(@org.jetbrains.annotations.NotNull()
^
e: /Users/nico/Dev/git/edreams/workshops/K-Places/data/build/tmp/kapt3/stubs/debug/com/edreams/android/workshops/kotlin/data/venues/remote/response/GroupsResponse.java:109: error: cannot find symbol
kotlinx.serialization.KSerializer<T0> typeSerial0) {
^
symbol: class T0
location: class $serializer
:data:kaptDebugKotlin FAILED
Okay, now I see. It's either serialization plugin produced not so correct descriptors or kapt can't transform such code
@sandwwraith any update on this? were you able to investigate this issue further?
@nico-gonzalez Yes. Unfortunately, there are some problems with internal plugin api, which doesn't allow to correctly specify type parameters in synthetic classes (such as serializers). This means this issue can't be resolved without changes in upstream compiler and next Kotlin update
I have the same problem.
Doesn't work when the new kapt plugin is used:
kotlin("jvm") version "1.2.31"
kotlin("kapt") version "1.2.31"
Works with internal kapt plugin and downgraded kotlin:
kotlin("jvm") version "1.2.20"
Starting from 1.2.50, this should not be a problem
@sandwwraith seems to be working now. I will test this further. Many thanks!!
@sandwwraith I'm using kotlin 1.2.51 and kapt, but unfortunately I couldn't build the project due to following error.
/home/test/android/app/build/tmp/kapt3/stubs/debug/io/github/alishir/test/profile/TestManager.java:7: error: type DeviceManager.DeviceManagerCallback does not take parameters
private final pkg.test.DeviceManager.DeviceManagerCallback<pkg.test.DeviceManagerCallbacks> mCallback = null;
^
@alishir I don't see how that's related to kotlinx.serialization... is your DeviceManagerCallback serializable?
@sandwwraith oh sorry I didn't check the exact error, you are right it is unrelated. Do you know where should I post issues about kapt?
@alishir Official Kotlin YouTrack, https://kotl.in/issue
@sandwwraith thanks a lot.
It seems that this problem still persists.
Sample code to reproduce:
@Serializable
data class GenericDataClass<T>(val genericProperty: T)
When used with any annotation processor, it causes kapt to fail with the following errors:
> Task :kaptKotlin FAILED
e: /foo/kotlinx-serialization-test/build/tmp/kapt3/stubs/main/GenericDataClass.java:51: error: non-static type variable T cannot be referenced from a static context
GenericDataClass<T> self, @org.jetbrains.annotations.NotNull()
^
e: /foo/kotlinx-serialization-test/build/tmp/kapt3/stubs/main/GenericDataClass.java:54: error: non-static type variable T cannot be referenced from a static context
kotlinx.serialization.KSerializer<T> typeSerial1) {
^
Here's the generated code in question:
public static final void write$Self(@org.jetbrains.annotations.NotNull()
GenericDataClass<T> self, @org.jetbrains.annotations.NotNull()
kotlinx.serialization.CompositeEncoder output, @org.jetbrains.annotations.NotNull()
kotlinx.serialization.SerialDescriptor serialDesc, @org.jetbrains.annotations.NotNull()
kotlinx.serialization.KSerializer<T> typeSerial1) {
}
Tested with:
@SpaceBison It's #429 .