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

查看:29
本文介绍了如何在 NDK 本机代码中获取断点并在 Android Studio 中调试本机代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NDK 开发 Android 应用程序.我有两个项目.一个是我的原生库,它使用 NDK 并生成 .so 文件.

I am developing android app using NDK. I have two projects. One is for my native library which uses NDK and generates .so file.

我正在使用 Android Studio,但使用 ndk-build 禁用自动构建和启用构建.我使用的是 Windows 7.

I am using Android Studio but disabling auto build and enabled build using ndk-build. I am using Windows 7.

现在在生成 .so 文件后,我将那些复制到我的主应用程序项目中,该项目也使用 ndk-build 来编译 JNI 函数,我在其中调用我的库函数.我希望到目前为止我是干净的.如果没有,那么我会根据要求提供更多详细信息.

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.

现在我正在使用 Android Studio 在设备中运行我的应用程序,我可以在 Java 代码中放置断点并调试该代码,但我无法调试 JNI 调用以及我在单独项目中拥有的本机代码.我需要在我的库代码中进行调试.那么有什么办法可以做到这一点吗?

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?

我看过 VisualGDB,但它是付费的.所以让我知道是否有任何替代方案可以完全满足我的调试要求.我已经搜索了很多但没有得到任何具体的解决方案.

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.

我可以在 Android Studio 中看到用于附加到 android 进程的选项,在那里我可以看到我正在运行的设备,但我不确定如何使用它,因此我可以通过本机库代码(在单独的项目中没有任何活动)进行调试.

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

推荐答案

在 Android Studio 2.0 预览中,过程有点不同(我认为更容易):

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

  1. 安装LLDB":进入工具->Android->SDK 管理器,然后进入SDK 工具"选项卡并确保选中LLDB"(靠近列表末尾)通常)
  2. 选择一个/Debug"变体:在AS的左下角,点击Build Variants",默认的debug变体叫做Debug"
  3. 选择原生配置:左侧的运行按钮(绿色三角形),默认的原生配置叫做app-native"
  4. 设置断点
  5. 在调试中启动您的应用,点击运行按钮右侧的小错误.
  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天全站免登陆