Why is “Decompile kotlin to java” greyed out in Android Studio 3.1.2

Issue

enter image description here

However, if I manually do “Show Kotlin Bytecode” and click on “Decompile” it will show the correct java code.

Solution

If you write some kotlin and want to see how it gets compiled into JAVA by using the Decompile Kotlin to Java menu, you need to be viewing the compiled .class file and not the Kotlin source .kt file.

After building the app, try to find the compiled *.kt file in the App/build/tmp/kotlin-classes directory. Here is a simple command line you can run in the root of your project to output the location if your Kotlin file is named Hello.kt:

find  ./ | grep "Hello.class"

Open the .class file in IntelliJ or Android Studio and the menu will be available to see how your Kotlin was converted to JAVA

Answered By – bsautner

Leave a Comment