No Debug information with remote debugger

Trying to attach a debugger client to my Kotlin project built by gradle with debug information such as source code.

Within project root I execute: ./gradlew test --debug-jvm.
After jdb -attach $PORT, I couldn’t list to view source code.

Any suggestions for me to setup debugging environment properly?

Make sure to execute JDB from correct location. Assuming you have downloaded this sample app and your emulator is running.


user@debian:<dir>/sample_building_android_apps-kotlin-dsl$ ./gradlew installDebug
user@debian:<dir>/sample_building_android_apps-kotlin-dsl$ cd app/src/main/java
user@debian:<dir>/sample_building_android_apps-kotlin-dsl/app/src/main/java$ adb shell am start -D -n org.gradle.samples/.MainActivity
user@debian:<dir>/sample_building_android_apps-kotlin-dsl/app/src/main/java$ adb forward tcp:8700 jdwp:<PID>
user@debian:<dir>/sample_building_android_apps-kotlin-dsl/app/src/main/java$ jdb -attach localhost:8700 -sourcepath /<dir>/sample_building_android_apps-kotlin-dsl/app/src/main/java

Pay attention to the 2nd line. If you do not change to the correct working directory you will not be able to list source code, even if you defined the correct -sourcepath for JDB. To get the correct PID, use adb shell ps | grep "org.gradle".