Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get breakpoint in NDK native code and debug native code in Android Studio?

Tags:

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

like image 780
Premal Avatar asked Feb 19 '15 09:02

Premal


People also ask

What is native code in Android Studio?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.

How do I enable debug on APK?

To start debugging an APK, click Profile or debug APK from the Android Studio Welcome screen. Or, if you already have a project open, click File > Profile or Debug APK from the menu bar. In the next dialog window, select the APK you want to import into Android Studio and click OK.


1 Answers

In Android Studio 2.0 preview the process is a bit different (ans easier I think):

  1. 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)
  2. Select a/the "Debug" variant: In the lower left corner of AS, click on "Build Variants", the default debug variant is called "Debug"
  3. Select a native configuration: left side of the run button (The green triangle),The default native configuration is called "app-native"
  4. Set a breakpoint
  5. 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".

like image 65
Sistr Avatar answered Sep 28 '22 03:09

Sistr