How To Debug Android Applications Without Using Android Studio IDE | Introduction To Java Debug Wire Protocol

With Android Studio IDE, the debugging of an Android apps is much easier. But if you have decided to develop an Android apps without using any IDE then this blog posts will be helpful for you.

See here why would anyone wants to develop Android apps or modules without Android Studio?

Disclaimer: This guide is provided "as is" with no warranties with regard to the accuracy and completeness of the information provided herein. I expect you to have an inquisitive mind to try things out, and the patience to first google and try to find answers to simple questions.


Introduction to JDB (Java Debugger)

JDWP is a very useful tools for debugging Java applications or any JVM-like applications. Since Android programs is basically a Java, we can use then the JDB to debug our Android applications.

How To Use The JDB

Let's get it to the point and straight to the process of using the JDB.
  1. Make sure you have the JDB on your machine.
  2. Make sure you have ADB (Android Debug Bridge).
  3. Build a debuggable version of your Android apps and do not minify it.
  4. Install the debuggable apps on a phone or emulator and run it.
  5. Find the process id of the apps in your phone or emulator.
    • Execute adb shell ps | grep <your application id>. The 2nd column from the result is usually the process id. You should replace the <your application id> with your actual project package name, you can find it in the manifest and build.gradle.
  6. Setup communication between ADB and JDB.
    • Execute adb forward tcp:<port> jdwp:<pid>
      • Replace the port and pid without actual values. The port must be unused.
  7. Attach the JDB.
    • Execute jdb -attach localhost:<port>. The port must be the one you setup in step 6.
  8. Execute JDB commands. Here's some useful JDB commands:
    • classes
    • methods
    • stop in
    • stop at
    • next
    • locals
    • print
    • cont
    • run
    • clear
See JDB manual for the list of all commands.

Comments

Popular posts from this blog

How To Check If Your Android Phone Is Official Or Rooted

Android Reverse Engineering - Beginners Guide To Smali Coding

Conquering macOS Upgrades: A Guide for iOS App Developers