首页 > 解决方案 > Getting "Conflicting overloads" for every function in one Kotlin file whenever I change it

问题描述

For one Kotlin file in my project, almost every time I make changes to it and rebuild, I get "Conflicting overload" messages for every function. There aren't two conflicting functions; each error message lists exactly the same function twice. If I do a clean build, it builds fine.

e: ContentApi.kt: (220, 1): Conflicting overloads: public fun loadExclusions(assetIds: List): Unit defined in com.foo.bar in file ContentApi.kt, public fun loadExclusions(assetIds: List): Unit defined in com.foo.bar in file ContentApi.kt

Changes to other Kotlin files don't produce the same problem. I can create a function in another Kotlin file, build with no trouble, then cut and paste it into this file, and boom.

Has anyone else seen something like this? My best guess is that it's some kind of bug with the compiled code cache where the newly compiled code doesn't replace the previous version, so they conflict with each other.

Android Studio/Gradle version 3.2 RC 3 Kotlin version 1.2.61

标签: androidandroid-studiogradlekotlin

解决方案


当您有两个名称相同但注释不同的函数时,通常会发生这种情况。

例如:

@PrePersist
public fun loadExclusions(assetIds: List){
}

@PreUpdate
public fun loadExclusions(assetIds: List){
}

推荐阅读