Invalid Method Declaration in Kotlin Enum Class building with gradle wrapper

Figured out what was going on. Android Studio & IntelliJ both are using a bundled JDK (AS 3.2.1 uses 1.8.0_152), so gradle was executing kapt in that environment. On my machine however I have Java 11 set as the default java. I use JENV to manage multiple java versions, so on a hunch I set the local java version to 1.8 rather than 11. Works fine after that.

My understanding is that the Kotlin compiler is supposed to emit Java 8 byte code that the Java 11 compiler should understand (I do the Kotlin compiler configured to do so in build.gradle), but apparently that's not true in this case.

Not really an answer to why it is happening, but it is a solution.


I had a similar error with an abstract enum function. Gradle was using JDK 11. Switching to JDK 8, by adding an org.gradle.java.home entry to gradle.properties (in your HOME/.gradle/gradle.properties or in your project specifig gradle.properties resolved the issue.

 echo 'org.gradle.java.home=PATH_TO_JDK8' >> ~/.gradle/gradle.properties