How to get breakpoint in NDK native code and debug native code in Android Studio?
I am developing android app using NDK. I have two projects. One is for my native library which uses NDK and generates .so file.
I am using Android Studio but disabling auto build and enabled build using ndk-build. I am using Windows 7.
Now after generating .so file I copy those in my main application project which also uses ndk-build to compile JNI functions in which I am calling functions of my library. I hope I am clean till this point. If not then I will give more detail on request.
Now I am running my application in device using Android Studio and I can put break point in java code and debug that code but I am not able to debug JNI call and also native code which I have in separate project. I need to debug inside my library code. So is there any way to achieve this?
I have seen VisualGDB but it is paid. So let me know if there is any alternative to full fill my debugging requirements.I have searched lot but did not get any concrete solution.
I can see option in Android Studio for attaching to android process where I can see my running device but I am not sure how to use it so I can debug by native library code (which is in separate project without any activity).
Let me know if more detail is required
3 Solutions collect form web for “How to get breakpoint in NDK native code and debug native code in Android Studio?”
In Android Studio 2.0 preview the process is a bit different (ans easier I think):
- Install “LLDB”: Go in Tools->Android->SDK Manager, then go in the “SDK Tools” tab and make sure to check “LLDB” (Near the end of the list usually)
- Select a/the “Debug” variant: In the lower left corner of AS, click on “Build Variants”, the default debug variant is called “Debug”
- Select a native configuration: left side of the run button (The green triangle),The default native configuration is called “app-native”
- Set a breakpoint
- Launch your app in debug by clicking on the little bug on the right side of the run button.
If it doesn’t work, check that your native configuration has debug type “Hybrid” selected: On the right of the play button, click the little triangle, select “Edit Configurations”, select your “app-native” configuration, go in the “Debugger” tab and select “Debug type: Hybrid”.
Android Studio 1.3+ supports native debugging.
To set it up, follow these steps:
- Modify your gradle-wrapper.properties, local.properties, and both build.gradle files as shown in this guide
- Sync gradle
Create and select new build configuration:
Click on drop down next to run button) -> Edit configurations, click plus sign, choose Android Native, fill in options on the right (I used LLDB in native debugger tab), and you should be set.
Set breakpoints in C++
- Hit debug button and be patient (sometimes the debugger takes a while)
I have been able to debug native code under Lubuntu 14.04 with Android Studio 1.3 (stable channel). Although others have supposedly been successful under Windows, I haven’t been able to debug natively in Windows 8.1 (I have tried with Android Studio 1.3, 1.3.2, and 1.4 preview 3).
Android Studio 1.4 Beta just came out. I tested it and was able to debug natively on Windows 8.1.
I was able to set breakpoints and step into native code but only when all of the following were true:
- The generated native library .so files retained their debug symbols
- Sources were supplied (see “Library Properties” menu)
- I set the run/build configuration to use a native debugger (as described here)
It is working for me right now in Android Studio 1.5, using the Gradle Experimental Plugin