Kotlinx.serialization: IntelliJ Idea: Unresolved reference: serializer

Created on 1 Nov 2018  路  36Comments  路  Source: Kotlin/kotlinx.serialization

Idea doesn't compile project files with an error: "Kotlin: Unresolved reference: serializer".
I tried various cleanup task and IDE restarting and a project reimport but it doesn't solve the issue.

Meantime gradle itself works perfectly without any errors.

build.gradle.kts

buildscript {
  repositories { jcenter() }

  dependencies {
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0")
    classpath("org.jetbrains.kotlin:kotlin-serialization:1.3.0")
  }
}

apply {
  plugin("kotlin")
  plugin("kotlinx-serialization")
  ...
}

dependencies {
  compile(kotlin("stdlib", "1.3.0"))
  compile("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.9.0")
  ...
}

Idea version

IntelliJ IDEA 2018.2.5 (Ultimate Edition)
Build #IU-182.4892.20, built on October 16, 2018
JRE: 1.8.0_152-release-1248-b19 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14

Idea kotlin plugin version:

1.3.0-release-IJ2018.2-1

Most helpful comment

This problem is back:

IntelliJ IDEA 2019.1.3 (Ultimate Edition)
Build #IU-191.7479.19, built on May 28, 2019
JRE: 1.8.0_202-release-1483-b58 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

serializer() function shows unresolved...

I see this intermittently day after day, not all the time, really weird.
Gradle build is all ok. Looks like it's the IDE.

All 36 comments

Hi, is it error on a highlighting level (.serializer() code is shown as red) or only compile error? If latter, delegate build in IDEA to Gradle (Settings - Build, Execution, Deployment - Build Tools - Gradle - Runner - tick Delegate IDE build/run actions to gradle).

It was a compilation error:

/Users/dima/apps/teamcity-sync/src/main/kotlin/me/dmexe/teamcity/sync/github/GithubQuery.kt
Error:(16, 38) Kotlin: Unresolved reference: serializer

16: JSON.stringify(ReposQuery.serializer(), query)

After I turned on "delegate build to gradle" a project compiles without errors. In 1.3 release notes "Serialization support should work out of the box, if you have 1.3 Kotlin plugin installed" is it still not true?

And the next sentence after the one you cited is about delegation to gradle. "Serialization support" was mainly for highlighting generated code. The issue with compilation is known and likely will be fixed in the next release.

@sandwwraith is there an issue (on GitHub or YouTrack) to keep track of when this compilation issue will be fixed? I can't seem to find it, but I may be using the wrong keywords in my search.

@jguerinet I think you can track this one: https://github.com/Kotlin/kotlinx.serialization/issues/265

@sandwwraith I'm having a similar issue with Unresolved reference: serializer being shown in red in IDEA. I've updated to latest versions (e.g. have the Kotlin 1.3 plugin installed and latest IDEA), maven compiles ok, I see the generated code, can run it fine, but can't get rid of the red highlighting.

I have the same issue as @tromper.
My project builds and works as expected using a maven build. With the build delegated to maven, serialization tests also build, run, and pass from IntelliJ. All references to the ".serializer()" method on any @Serializable class show up as an error in IntelliJ's linter (red highlight. File defining them has a red underscore).
It's not a show stopper, since the build works, but it's annoying, particularly when a new developer starts on the project (s/he always spends a few hours trying to fix the "Unresolved reference", no matter how much we try to document the linter failure) .

Hm, probably this is a particular Maven import issue, since Gradle projects with serialization are imported into IDE correctly. I'll check this out.

That sounds right. I haven't seen this on my personal projects (which are gradle projects). Only on this one at work (where we use maven)

@grahamcummins-wf Indeed, you can track #307

@sandwwraith I have the same Issue, but with a gradle project. I haven't been able to get rid of the synta highlighting.

@IARI Have you tried reimporting project/deleting .idea folder? Is Kotlin plugin in IDEA higher than 1.3? Does Gradle build passes correctly?

@sandwwraith
Kotlin and IDEA plugin ist 1.3.11, Gradle build passes correctly.
I was able to get rid of it temporarily, I think by reimporting the project. but I'll have to try that again to be sure.

@sandwwraith I also have the syntax highlighting issue with a Gradle project (Kotlin DSL). I tried deleting the .idea folder. Kotlin plugin version is 1.3.20. And I am using Android Studio 3.4 beta 3.
Try to clone this:
https://github.com/clhols/drchannels
And open AppUpdater.kt on line 77.

@sandwwraith For me the problem is fixed by deleting the .idea folder, but I have to do it often.

yep it is fixxed temporarily for me by reimporting the gradle project. but that only lasts until i think idea is restarted oder something else changes

Same here, project compiles, but Intellij can't resolve the serializer() extension.

Same. Updating gradle dependencies / deleting the .idea folder fixes the issue until i restart the idea.

Same here, IDEA highlights it in red but all runs.
screenshot

Have same highlighting issue of serializable() in Android Studio. Does not go away even after "Invalidate Caches & Restart"

@fracturizer @coder82 Can you please write versions of your IDEs?

Same here with a multi module android project

Android studio 3.3.2

Android Studio 3.2.1
Build #AI-181.5540.7.32.5056338, built on October 9, 2018
JRE: 1.8.0_152-release-1136-b06 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

BTW. Highlighting problem was gone after deleting .idea folder and clean build.

This problem is back:

IntelliJ IDEA 2019.1.3 (Ultimate Edition)
Build #IU-191.7479.19, built on May 28, 2019
JRE: 1.8.0_202-release-1483-b58 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

serializer() function shows unresolved...

I see this intermittently day after day, not all the time, really weird.
Gradle build is all ok. Looks like it's the IDE.

Problem still exists with IDEA 2019.2 and Kotlin plugin 1.3.50-eap-5.

Have you tried to reimport the project?

Yes, it fixes it, but i have to do it every time i start the IDE...

To me it doesn鈥檛 fix it by restarting, I also have to delete the gradle.xml from .idea dir to fix it.
Really annoying because restarting means quite a lot of reload, reindex, reimport etc...
This should be reopened IMO.

None of the above options worked for me.

Using
IntelliJ IDEA 2019.1.1 (Community Edition)
Build #IC-191.6707.61, built on April 16, 2019
JRE: 1.8.0_202-release-1483-b44 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-30-generic

gradle would compile well. But IDEA would highlight ClassName.serializer() (the serializer method) and state that it is an "unresolved reference"

I have the same problem in Android Studio.

@fracturizer @coder82 Can you please write versions of your IDEs?

It's long I don't see this anymore, it was happening with the version I wrote above.
Now this is what I got:

IntelliJ IDEA 2019.2.2 (Ultimate Edition)
Build #IU-192.6603.28, built on September 6, 2019
Licensed to xxx
Subscription is active until July 6, 2020
Runtime version: 11.0.3+12-b304.56 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 16
Registry: debugger.watches.in.variables=false
Non-Bundled Plugins: CMD Support, Lombook Plugin, mobi.hsz.idea.gitignore, org.jetbrains.plugins.hocon, org.jetbrains.kotlin, org.jetbrains.debugger.streams.kotlin, com.deadlock.scsyntax, com.dmarcotte.handlebars, com.flageolett.nodeconfig

...Pretty sure this is back. Why is gradle so horrible/indecipherable to use...every time I've tried to use kotlin it has just been this massive hacky mess in gradle...

IntelliJ 2019.2.3 does not see the serialization stuff. Only the 1.2 stuff seemed to work.

Update

So I figured out that Kotlin 1.3 plain doesn't work with JDK 1.8... which seems like a general issue with the platform? I get JDK 11 is great and all that but most java code exists compiled for 8...

This was fixed a long time ago for me, couple of things if you haven't checked already, make sure gradle is up to date, make sure the serilization dep is up to date, make sure kotlin is up to date (as it's bundled into the compiler plugin). Make sure you have cleaned and then invalidated caches.
IF after all of that it still doesn't work, please create a minimum reproduceable example and create a ticket so they can fix it.

Yes, I faced the same issue when developing multiplatform applications.
I resolved it by adding to _build.gradle_:

plugins {
    ...
    id 'org.jetbrains.kotlin.multiplatform'
    id 'kotlinx-serialization'
}

and also

buildscript {
    ...
    dependencies {
        ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVer"
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVer"
    }
}

where _kotlin_version = 1.3.61_

I ran into the same issue on kotlin_version=1.3.60 and resolved it by rebuild the project after switching to kotlin_version=1.3.50. The bug is constantly reproducible and resolvable to me.

Just reproduced using IntelliJ IDEA / Maven:

  • Error: _Error:(83, 53) Kotlin: Unresolved reference: serializer_
  • IDE: _IntelliJ IDEA 2018.2.2 (Community Edition)_
  • pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
聽 聽 聽 聽 聽xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
聽 聽 <modelVersion>4.0.0</modelVersion>

聽 聽 <groupId>tld.group</groupId>
聽 聽 <artifactId>artifact</artifactId>
聽 聽 <version>1.0.0-SNAPSHOT</version>

聽 聽 <name>artifact</name>
聽 聽 <description>description</description>

聽 聽 <properties>
聽 聽 聽 聽 <kotlin.version>1.3.61</kotlin.version>
聽 聽 聽 聽 <serialization.version>0.14.0</serialization.version>
聽 聽 聽 聽 <kotlin.compiler.incremental>true</kotlin.compiler.incremental>
聽 聽 聽 聽 <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
聽 聽 聽 聽 <main.class>MainClass</main.class>
聽 聽 </properties>

聽 聽 <dependencies>
聽 聽 聽 聽 <dependency>
聽 聽 聽 聽 聽 聽 <groupId>org.jetbrains.kotlin</groupId>
聽 聽 聽 聽 聽 聽 <artifactId>kotlin-stdlib</artifactId>
聽 聽 聽 聽 聽 聽 <version>${kotlin.version}</version>
聽 聽 聽 聽 </dependency>
聽 聽 聽 聽 <dependency>
聽 聽 聽 聽 聽 聽 <groupId>org.jetbrains.kotlinx</groupId>
聽 聽 聽 聽 聽 聽 <artifactId>kotlinx-serialization-runtime</artifactId>
聽 聽 聽 聽 聽 聽 <version>${serialization.version}</version>
聽 聽 聽 聽 </dependency>
聽 聽 </dependencies>

聽 聽 <build>

聽 聽 聽 聽 <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
聽 聽 聽 聽 <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

聽 聽 聽 聽 <plugins>
聽 聽 聽 聽 聽 聽 <plugin>
聽 聽 聽 聽 聽 聽 聽 聽 <groupId>org.jetbrains.kotlin</groupId>
聽 聽 聽 聽 聽 聽 聽 聽 <artifactId>kotlin-maven-plugin</artifactId>
聽 聽 聽 聽 聽 聽 聽 聽 <version>${kotlin.version}</version>
聽 聽 聽 聽 聽 聽 聽 聽 <configuration>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <experimentalCoroutines>enable</experimentalCoroutines>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <plugin>kotlinx-serialization</plugin>
聽 聽 聽 聽 聽 聽 聽 聽 </configuration>
聽 聽 聽 聽 聽 聽 聽 聽 <executions>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <execution>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <id>compile</id>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <goals>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <goal>compile</goal>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </goals>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </execution>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <execution>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <id>test-compile</id>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <goals>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <goal>test-compile</goal>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </goals>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </execution>
聽 聽 聽 聽 聽 聽 聽 聽 </executions>
聽 聽 聽 聽 聽 聽 聽 聽 <dependencies>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <dependency>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <groupId>org.jetbrains.kotlin</groupId>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <artifactId>kotlin-maven-serialization</artifactId>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <version>${kotlin.version}</version>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </dependency>
聽 聽 聽 聽 聽 聽 聽 聽 </dependencies>
聽 聽 聽 聽 聽 聽 </plugin>
聽 聽 聽 聽 聽 聽 <plugin>
聽 聽 聽 聽 聽 聽 聽 聽 <groupId>org.apache.maven.plugins</groupId>
聽 聽 聽 聽 聽 聽 聽 聽 <artifactId>maven-assembly-plugin</artifactId>
聽 聽 聽 聽 聽 聽 聽 聽 <version>2.6</version>
聽 聽 聽 聽 聽 聽 聽 聽 <executions>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <execution>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <id>make-assembly</id>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <phase>package</phase>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <goals>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <goal>single</goal>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </goals>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <configuration>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <archive>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <manifest>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <mainClass>${main.class}</mainClass>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </manifest>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </archive>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <descriptorRefs>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 <descriptorRef>jar-with-dependencies</descriptorRef>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </descriptorRefs>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </configuration>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 </execution>
聽 聽 聽 聽 聽 聽 聽 聽 </executions>
聽 聽 聽 聽 聽 聽 </plugin>
聽 聽 聽 聽 </plugins>

聽 聽 </build>

</project>
Was this page helpful?
0 / 5 - 0 ratings