需要手机Android项目中的崩溃信息到文件中,然后上传服务器。我现在知道怎么收集Android的崩溃信息到文件中,也知道如何上传服务器。但是我的项目中有cocos的代码,我怎么能收集到cocos的崩溃信息呢?
我看过http://www.cnblogs.com/lancidie/archive/2013/04/13/3019349.html这里面的内容,想试着做出来,但是在把jni部分的代码粘进去以后,出现了很多错误,代码如下:
#include "cocos2d.h"
#include
#include "platform/android/jni/JniHelper.h"
#include "BookManager.h"
#include "jniIF.h"
#include "LeFileManager.h"
#include "StatisticalData.h"
#include "ConfigFile.h"
#include "StorePage.h"
#include "signal.h"
#include "unistd.h"
#include "errno.h"
using namespace cocos2d;
extern "C" {
//尝试捕获cocos的奔溃信息
//思路是,当发生崩溃的时候,在回调函数里面调用一个我们在Activity写好的静态函数。
//在这个函数里面通过执行命令获取logcat的输出信息(输出信息里面包含了jni的崩溃地址),然后上传这个崩溃信息。
//当我们获取到崩溃信息后,可以通过arm-linux-androideabi-addr2line(具体可能不是这个名字,在android ndk里面搜索*addr2line,找到实际的程序)解析崩溃信息。
//jni的崩溃回调函数如下
//#define sigaction(X, &handler, &old_sa[X])
void android_sigaction(int signal, siginfo_t *info, void *reserved) {
JniMethodInfo t;
if (!t.env) {
return;
}
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "onNativeCrashed",
"()V")) {
jmethodID methodID = t.env->GetStaticMethodID(t.classID,
"onNativeCrashed", "()V");
}
t.env->CallStaticVoidMethod(t.classID, t.methodID);
old_sa[signal].sa_handler(signal);
}
//通过singal的设置,当崩溃发生的时候就会调用android_sigaction函数。
void InitCrashReport() {
CCLOG("InitCrashReport");
// Try to catch crashes...
struct sigaction handler;
memset(&handler, 0, sizeof(struct sigaction));
handler.sa_sigaction = android_sigaction;
handler.sa_flags = SA_RESETHAND;
#define CATCHSIG(X) sigaction(X, &handler, &old_sa[X])
CATCHSIG(SIGILL);
CATCHSIG(SIGABRT);
CATCHSIG(SIGBUS);
CATCHSIG(SIGFPE);
CATCHSIG(SIGSEGV);
CATCHSIG(SIGSTKFLT);
CATCHSIG(SIGPIPE);
}
}
错误如下:
我是做Android的,对c++的代码基本不懂,希望各位能帮个忙,谢谢大家了