Dabbler
Dabbler

Reputation: 9873

Why does implementing the Cloneable Interface in a Kotlin class result in "error: no interface expected here"?

I'm resuming work on an Android app that I haven't touched for a year. It used to build fine at the time. Now when I open it in Android Studio it complains that various libs, plugins, etc. are out of date. Trying to fix this myself, I couldn't get rid of all the sync/build errors, so in the end I updated Android Studio (from around 3.3, I think) to 3.5.2 and let it update whatever plugins etc. it wanted to.

Then I ran into issues indicating I should migrate from the old support packages to AndroidX (don't remember the details). To migrate, I then did the following:

Now Gradle sync works, but building fails with this error:

> Task :app:kaptDebugKotlin FAILED
e: [...]\app\build\tmp\kapt3\stubs\debug\com\[...]\MyClass.java:9: error: no interface expected here
public final class MyClass extends java.lang.Cloneable {
                                           ^

FAILURE: Build failed with an exception.

The above error is in generated code. My code, from which the above is generated, looks like this:

// MyClass.kt
class MyClass : Cloneable {
...
}

I understand java.lang.Cloneable is an interface, and the generated code has extends instead of implements. But as mentioned, this used to work, so what am I doing wrong?

Upvotes: 2

Views: 352

Answers (1)

Dabbler
Dabbler

Reputation: 9873

I took another look at the project-level build.gradle and found it. Android Studio was suggesting to update the Kotline version again. I changed it to

ext.kotlin_version = '1.3.61'

and now I can compile.

Upvotes: 1

Related Questions