gpt4 book ai didi

android - 如何使用 Eclipse 在 Android 上调试 C++ 代码?

转载 作者:太空狗 更新时间:2023-10-29 16:20:51 24 4
gpt4 key购买 nike

我在 PC 上编写了一些视频流 (C++),现在我尝试在 Android 上实现相同的跨平台部分。我充分“玩”了 NDK 并了解了一些关于如何编译 C 代码并将其与 Android(又名 JNI)集成的知识。

问题是有时我的应用程序会崩溃,而且如您所知,Android 不会指出代码失败的地方(在 C/C++ 部分)。

Video Streamer 代码有很多库,可以说,我使用的开源部分是为了留下日志——这不是个好主意。我使用 Eclipse,如何调试 C++ 代码或者 Eclipse 是否有任何插件可以调试?

非常感谢,

最佳答案

要记录内容并在 Android 的 logcat 中查看它,我有一个简单的类:

#ifndef LOG_H_
#define LOG_H_

#include <android/log.h>

#define LOGD(LOG_TAG, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGI(LOG_TAG, ...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGV(LOG_TAG, ...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#define LOGW(LOG_TAG, ...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGE(LOG_TAG, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

#endif /* LOG_H_ */

你可以这样使用它:

LOGI("YourClassTag","let's print some stuff: %i, %s", 4, "I'm a string");

要获取有关某些崩溃的更多信息,您可以尝试启用 JNICheck与亚行:

If you have a regular device, you can use the following command:

adb shell setprop debug.checkjni 1

This won’t affect already-running apps, but any app launched from that point on will have CheckJNI enabled. (Change the property to any other value or simply rebooting will disable CheckJNI again.) In this case, you’ll see something like this in your logcat output the next time an app starts:

D Late-enabling CheckJNI

关于android - 如何使用 Eclipse 在 Android 上调试 C++ 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15347994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com