Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

enter image description here

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

like image 322
WenChao Avatar asked May 25 '18 06:05

WenChao


People also ask

How do I enable Decompile Kotlin in Java?

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

Can you use Kotlin and Java in the same project Android Studio?

Android Studio provides full support for Kotlin, enabling you to add Kotlin files to your existing project and convert Java language code to Kotlin. You can then use all of Android Studio's existing tools with your Kotlin code, including autocomplete, lint checking, refactoring, debugging, and more.

Can Kotlin be decompiled?

A helper plugin to support decompiler Kotlin bytecode to Java. It is based on CFR Decompiler which doesn't have problems to decompile the bytecode with Kotlin Coroutines. It can be also used for checking the result of Jetpack Compose.


2 Answers

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

like image 93
bsautner Avatar answered Sep 20 '22 11:09

bsautner


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.

like image 40
VSMent Avatar answered Sep 18 '22 11:09

VSMent