25

enter image description here

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

0

5 Answers 5

23

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

8

Another option for viewing Kotlin decompiled code is to open Kotlin bytecode tab and press Decompile there.

Go to Tools -> Kotlin -> Show Kotlin Bytecode press Decompile in the header.

Works for IntelliJ IDEA 2019.3, so I believe it would work in Android Studio as well.

3

Install the plugin Kotlin to Java decompiler in android studio. Open the kotlin file in the editor Run the action from Code -> Decompile Kotlin to Java

1

Answer:
              Because, Even after the update of latest Kotlin version ,Sometimes Plugins for Kotlin to Java Decompiler is disabled (OFF).In Order to Enable it, click on Help from the toolbar of Android studio Help

Go to Find Action or Press(Ctrl+Shift+A) Now Click on Actions Tab and search for "Decompile Kotlin to Java" Select the Plugin "Decompile Kotlin to Java" and if it is "OFF" toggle it to "ON" Image of Plugin

Finally, Go to Tools tab >> find Kotlin >> Show Kotlin Bytecode Image for reference

A new tab will open on the left
Image of Decompile

0

Install Kotlin to Java Decompiler

enter image description here

Then go to tools->kotlin-> show kotlin bytecode to see byte code information.

you can further check the java equivalent code by using Decompile button in the bytecode window.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.