Tuesday, 2 July 2019

Kotlin file changes result in Redeclaration error

Every change to a kotlin file results in a Redeclaration error when building. The only way around it is by cleaning the project and then rebuilding. There are no other files in the project with the same name as the files I am editing.

I have tried:

  • Renaming the class I have been working on
  • Upgrading and downgrading the version of kotlin, gradle and kotlin plugin in Android Studio
  • Using beta Android Studio
  • Reordering the plugins in my gradle file

The current build is using:

org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21 com.android.tools.build:gradle:3.2.0

Example code that will cause the error. If I build without the addedThisLine it works as its the first build. Then when I edit the file in anyway it will cause the error below.

package beagle.com

class ErrorFragment {

    val hello = "Hello"

    init {
        var goodbye = "goodbye"
        var addedThisLine = "When this line is added I get error"
    }
}

Error that I get

Redeclaration Error

This happens in every kotlin file in my project, the code I posted above is the most basic file. As you can see it points to the name of the class for the error.



from Kotlin file changes result in Redeclaration error

No comments:

Post a Comment