14

Is it possible to view Dalvik bytecode for my app in Android Studio? If so, how?

Update:

My app is written in Java using Android Studio and I want to see my Java classes byte code, which is also known as Dalvik bytecode, (not the source code) inside Android Studio.

User
  • 277
  • 4
  • 13
  • what do you mean? You can open the class file. Also when you click on a function in your code, that belongs to a class that has no source code, it decompiles and displays the "skeleton" of the class – Gavriel Jan 12 '16 at 22:14
  • My app is written in Java using Android Studio and I want to see my Java classes byte code, which is also known as Dalvik bytecode, (not the source code) inside Android Studio. – User Jan 16 '16 at 22:42
  • You can open the files under $your_project/build/intermediates/classes. However as a feature Android Studio will try to show you the source if possible, or decompile it if it's not. You might try to change the file extension , or even easier just open it in any dumb text editor, even better in a hex editor. But why would you want to do that anyway? – Gavriel Jan 17 '16 at 06:34
  • @ Gavriel, I tried to open my MainActivity.class inside $my_project/build/intermediates/classes using text editors but I don't see any Dalvik byte code. Just for your info Dalvik byte code looks like [this] (https://source.android.com/devices/tech/dalvik/dalvik-bytecode.html) – User Jan 17 '16 at 23:38
  • so what do you see instead? – Gavriel Jan 17 '16 at 23:42
  • I see gibberish (seems to be binary content). What I want to see is Dalvik byte code in text format so I can read it and reason about it similar to this one here http://set.ee/jbe/ but in Android Studio. – User Jan 17 '16 at 23:59
  • That "gibberish" is the bytecode :) If you open it with a HEX editor, and look at the link you sent above about the dalvik-bytecode, you might be able to reason. Good luck with it :) – Gavriel Jan 18 '16 at 00:02
  • Java bytecode is not the same thing as Dalvik bytecode. The bytecode, as well as the containing file format, are entirely different. There are various tools for disassembling DEX files, including `dexdump` (part of Android, might even be installed on the device) and baksmali (https://github.com/JesusFreke/smali). – fadden May 31 '16 at 17:36

2 Answers2

14

It is now possible to inspect bytecode directly from Android Studio (Since version 3.0 Canary 1). Go to Build-> Analyze APK..., select your APK file. Navigate too class you are interested in, right click on it and select "Show Bytecode". You can also use your mapping file if your APK file is generated with Proguard.

Android Studio Show Bytecode

Jan Slominski
  • 2,968
  • 4
  • 35
  • 61
  • 1
    Hello, Any of way can show the bytecode of files quickly? now I have to click the right button and then click the 'Show Bytecode' to look the file, It's too slowly if I have to check lots of files in bytecode. – Chinese Cat Feb 10 '18 at 08:56
  • Any way to find my class quickly? I have about 16 classes.dex files – htafoya Jul 24 '19 at 16:48
0

the apk-package of you app contains the file classes.dex which you can disassemble using tools like baksmali to get the Dalvik bytecode.