Search code examples
androidcompilationdecompiling

How does Android compile a Java method to an compiled method?


Recently I decompiled some Android APKs with dex2jar, jd-gui and Android studio.

Why can some classes' methods see the source code, and some classes' method can only see /compiled code/?
What's the difference between these two class when compiling?

What's more, I want to do the same compile work to my code to ensure the security. What tools can I look for ?


Solution

  • When Android Studio opens a .class file and cannot decompile the code, it just displays the "compiled code" message. There are lots of things that could prevent a decompilation because a lot of stuff is legal in byte code that is illegal in Java. (For instance, it's perfectly legal byte code to have a method named if or for, but those are Java keywords and cannot be used to name a Java method.) These sorts of things can easily show up when the .class files are processed by ProGuard, and possibly by other tools in the APK build process.