如何使用 Android Studio 2.2.3 调试外部本机库的 C++ 源代码? [英] How can I debug C++ source code of an external native library using Android Studio 2.2.3?

查看:40
本文介绍了如何使用 Android Studio 2.2.3 调试外部本机库的 C++ 源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 Android Studio 2.2.3 在 Windows 10 下创建的 android 项目,该项目通过其包装器 jar(通过 JNI)使用本机库.本机库由qmake 在Android Studio 之外构建,它将使用android NDK r13b 中的GCC 4.9 生成本机共享库,代码使用-g 选项编译.

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.

为了使用这个原生库,我将包装器 jar 放在 /app/libs 目录下,将原生库放在 /app/src/main/下jniLibs/armeabi-v7a,一切正常,我可以从java代码成功调用本机库中实现的方法.

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.

问题是我调试这个android项目的时候,我在cpp文件中设置的断点没有生效,请注意cpp文件不在android项目的源码树中,我只是从安卓工作室.我已经安装了最新的 LLDB 并以混合"调试类型开始调试,我还使用图像列表"LLDB 命令来确认调试时加载的本机库图像是未剥离的版本.但是断点不会命中.

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.

我的配置有什么问题?

有人能给我一些建议吗?

Can somebody give me some suggestion?

谢谢!

推荐答案

如果您的程序在预编译代码上运行,您如何期望 AndroidStudio 到达您的断点?如果您在 Notepad++ 应用程序中的源代码中放置断点,则情况相同.相反,您必须告诉您的项目/代码使用源代码而不是预编译的库.为此,请删除所有 .so 文件并链接源代码,以便 NDK 从那里编译.

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.

这篇关于如何使用 Android Studio 2.2.3 调试外部本机库的 C++ 源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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