如何在 NDK 原生代码中获取断点并在 Android Studio 中调试原生代码? [英] How to get breakpoint in NDK native code and debug native code in Android Studio?

查看:31
本文介绍了如何在 NDK 原生代码中获取断点并在 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

解决方案

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".

这篇关于如何在 NDK 原生代码中获取断点并在 Android Studio 中调试原生代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆