15

I have an android project created by Android Studio 2.2.3 under Windows 10, this project use a native library through its wrapper jar (through JNI). The native library was built outside of Android Studio by qmake, which will use GCC 4.9 in android NDK r13b to generate the native shared library, the code was compiled with -g option.

To use this native library, I put the wrapper jar under <proj_path>/app/libs directory and the native library under <proj_path>/app/src/main/jniLibs/armeabi-v7a, everything works fine, I can successfully call the method implemented in the native library from java code.

The problem is that when I debug this android project, the breakpoint I set in the cpp file doesn't take effect, please note that the cpp file is not in the source tree of the android project, I just open it from android studio. I have installed the latest LLDB and I start debug with 'Hybrid' debug type, I also use 'image list' LLDB command to confirm that the native library image loaded when debugging is the unstripped version. But the breakpoint just won't hit.

What is wrong with my configuration?

Can somebody give me some suggestion?

Thanks!

shizhen
  • 12,251
  • 9
  • 52
  • 88
Liang Jian
  • 151
  • 5
  • Do you have some news? I think I have the same problem. I have read a ton of post about this problem and i don't found any real solution. I also posted a [question](https://stackoverflow.com/questions/46488591/how-can-i-debug-android-native-c-library-compiled-externally-with-cmake) because some days ago i didn't have the reputation to comment here. Thank you. – AndreaT Oct 05 '17 at 10:03
  • related: https://stackoverflow.com/questions/8674434/debugging-native-libraries-for-android-os/47132384 – Ciro Santilli OurBigBook.com Nov 06 '17 at 08:17
  • Android JNI debugging does not support debug native libraries, you have to enclose the C/C++ source code. – shizhen Dec 13 '18 at 05:39
  • Definitely add the source code to your project and make sure its dependencies are installed. – James Smith May 02 '23 at 05:33

1 Answers1

-1

How do you expect the AndroidStudio to hit your breakpoint if your program is running over the pre-compiled code? It would be the same if you put a breakpoint in the source-code say in your Notepad++ application. Instead, you have to tell your project/code to use the source-code and not the pre-compiled lib. For this, remove all the .so files and link the source-code so NDK will compile from there.

EDIT :
Apparently the -g flag is the magic part I missed. Some reference as a starting point for someone who wants to dig more about this flag is here: https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_16.html Personally I have never needed it, but it may be handy for some other cases. Although not sure if Android Studio is supporting it. Anyway, the clean-way remains including the source-code in your NDK application for debugging purposes and to be sure what you're debugging ;)

Hack06
  • 963
  • 1
  • 12
  • 20
  • 1
    -1 because: You may have compiled your source code in the debug mode (as in the question mentioned "it was built with `-g` flag) outside of the project and try to debug in Android Studio while having the symbols resolved normally. I'm not particularly sure how it's done, but it's definitely possible. – arsdever Jun 28 '23 at 20:49
  • Thanks, I wasn't aware of such a possibility to debug a pre-built executable with -g flag. I will update my answer. – Hack06 Aug 11 '23 at 19:25