简体   繁体   English

如何调试没有ndk-build构建的Android项目

[英]How to debug an Android project built without ndk-build

I try to debug a very basic example Qt 5.3 Android native C++ project, and I would like to debug it on the target without using QtCreator or any other IDE like Eclipse but only NDK tools. 我尝试调试一个非常基本的示例Qt 5.3 Android本机C ++项目,并且我想在目标上调试它而不使用QtCreator或任何其他IDE(如Eclipse),而仅使用NDK工具。 This project is compiled through QtCreator tools using Android platform target, in debug mode (-O0, -g), using NDK toolchain, BUT NOT ndk-build. 该项目是通过QtCreator工具使用Android平台目标通过调试模式(-O0,-g),使用NDK工具链(但不是ndk-build)进行编译的。

Therefore I got my .apk, the application itself has been installed on the target and works, everything is fine up to that point. 因此,我得到了.apk,应用程序本身已经安装在目标上并可以正常工作,到那时为止一切都很好。 Now I want to execute it in debug mode using NDK tools. 现在,我想使用NDK工具在调试模式下执行它。

I would like to use ndk-gdb as this seems to be one of the most obvious ways, therefore: - I created manually required files under my main project directory: 我想使用ndk-gdb,因为这似乎是最明显的方法之一,因此:-我在主项目目录下手动创建了所需文件:

bin
src
res
...
jni
|-- Android.mk
`-- Application.mk
libs
|-- armeabi-v7a
|   |-- gdbserver
|   |-- gdb.setup

The tree above only underline the files I added by hand, given that they are normally created by ndk-gdb. 鉴于它们通常是由ndk-gdb创建的,因此上面的树仅在我手动添加的文件下划线。 Under the 'libs' directory is also stored the native library of the project, called by a simple java wrapper. 在“ libs”目录下还存储了项目的本机库,该库由一个简单的Java包装器调用。

jni/Android.mk and jni/Application.mk contains the same single line: jni / Android.mk和jni / Application.mk包含同一行:

APP_ABI := armeabi-v7a

gdb.setup: gdb.setup:

set solib-search-path ./libs/armeabi-v7a
directory <myrootdir>/NDKToolchain/sysroot/usr/include <myrootdir>/NDKToolchain/include/c++/4.6 <myrootdir>/NDKToolchain/include/c++/4.6/arm-linux-androideabi/armv7-a [...]

I checked that the target was connected and accessible by installing the application using adb: 我通过使用adb安装应用程序来检查目标是否已连接并可以访问:

% adb install -r bin/QtApp-debug.apk

It worked ('success'), which I could check directly on the target. 它成功了(“成功”),我可以直接检查目标。

Then when I try to run ndk-gdb, it failed: 然后,当我尝试运行ndk-gdb时,它失败了:

% ndk-gdb --start --nowait --verbose

WARNING: The shell running this script isn't bash.  Although we try to avoid bashism in scripts, things can happen.
ndk-gdb: 84: Bad substitution
Android NDK installation path: [...]
Using default adb command: [...]/sdk/platform-tools//adb
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags: 
Using JDB command: 
Using auto-detected project path: .
Found package name: org.qtproject.example.fridgemagnets
ABIs targetted by application: armeabi-v7a
Device API Level: 18
Device CPU ABIs: armeabi-v7a armeabi
[: 564: 1: unexpected operator
Compatible device ABI: armeabi-v7a
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: [...]/ndk/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-
Using app out directory: ./libs/armeabi-v7a
Found debuggable flag: false
Found gdb.setup under libs/armeabi-v7a, assuming app was built with NDK_DEBUG=1
ERROR: Could not extract package's data directory. Are you sure that
       your installed application is debuggable?

A previous run of ndk-gdb showed me that for some reason it wanted to use ./obj/local/armeabi-v7a as "app out directory", while I set it in gdb.set to ./libs/armeabi-v7a, therefore I had to hack the ndk-gdb script to force it to use the path I chosed. 以前的ndk-gdb运行表明,由于某种原因,它想使用./obj/local/armeabi-v7a作为“应用程序输出目录”,而我在gdb.set中将其设置为./libs/armeabi-v7a,因此,我不得不破解ndk-gdb脚本,以使其强制使用我选择的路径。 I don't believe this is related to my real issue (?) 我不认为这与我的真实问题有关(?)

Given that I didn't use ndk-build, I believe that my attempt to use ndk-gdb is hopeless, or at least that it will ask me too much work and hacking of NDK scripts which I don't want to do. 考虑到我没有使用ndk-build,我相信我尝试使用ndk-gdb是没有希望的,或者至少它会问我太多的工作和我不想做的NDK脚本黑客。

Thus 2 questions: 因此有两个问题:

  1. Did I miss something during my build or deployment for getting a debuggable app ? 我在构建或部署过程中是否错过了一些可调试的应用程序? I know that debuggable flag in Manifest being 'false' is not necessarily an issue, as I built my app with debug flags. 我知道清单中的可调试标志为“ false”不一定是问题,因为我使用调试标志构建了应用程序。 BTW this seems to be confirmed by the fact that the error message I get is not related to that flag but to the fact that the script seems to exepect a DATA_DIR folder somewhere... 顺便说一句,这似乎可以通过以下事实得到证实:我收到的错误消息与该标志无关,而与脚本似乎在某个地方存在DATA_DIR文件夹的事实有关...
  2. Is there a way to debug my application, without using ndk-gdb (and any IDE), but for example just 'gdb' ? 有没有一种方法可以调试我的应用程序,而无需使用ndk-gdb(和任何IDE),例如,仅使用'gdb'?

Thanks in advance 提前致谢

Question 1: 问题1:
I know that as of SDK r8 you can invoke ant with release or debug . 我知道从SDK r8开始,您可以使用releasedebug调用ant。 Building with the debug flag might package or run your application differently. 使用debug标志进行构建可能会以不同方式打包或运行您的应用程序。 Thus allowing or disallowing debugging? 因此是允许还是不允许调试? This seems like it might be the issue. 这似乎是问题所在。

Question 2: 问题2:
From what I understand ndk-gdb does a lot of setup and communication with adb to allow debugging your application, as you may have seen from the script. 据我了解,ndk-gdb与adb进行了大量设置和通信,以调试您的应用程序,正如您从脚本中可能已经看到的那样。 I wouldn't suggest going down the rabbit hole of not using it. 我不建议您不要使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM