hansemannn / titanium-crashlytics

Use the native Crashlytics SDK in Titanium (iOS / Android).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crashlytics not sending any report.

cmtanko opened this issue · comments

I followed everything in the readme section. I was able to build and register the app in the crashlytics.

ISSUE:

  • I don't get any log or any report in the crashlytics dashboard for normal crash or crashlytics.crash(), it's just empty with the correct number of devices that has the app installed in it.

I do not get any error during the build, Am I missing something or some issue with the titanium-crashlytics package?

commented

I think the problem might be that TiExceptionHandler is receiving the error and logging it but that error is not propagated further and the application doesn't actually crash. Even when I cause a javascript error like: var a = null; a.callBadMethod(); the TiExceptionHandler is trapping and logging it. Crashlytics doesn't appear to be receiving the error information.

@hansemannn are you seeing evidence of the crashlytics.crash() function propagating past TiExceptionHandler so Crashlytics can report on the error?

Here is an example stacktrace of what I'm seeing below. It is an uncaught error but it is being caught so Android exception handlers aren't seeing it. I haven't tried rethrowing the error onwards yet...

Maybe the key is that although ti.crashlytics is a native module, V8 is still viewing this as a javascript error:

05-28 19:30:54.544: E/V8Exception(4025): Exception occurred at /ui/AppFrame.js:13802: Uncaught Error: length=2; index=10

05-28 19:30:54.544: E/TiExceptionHandler(4025): (main) [5035,5914] /ui/AppFrame.js:13802
05-28 19:30:54.544: E/TiExceptionHandler(4025): crashlytics.crash());
05-28 19:30:54.544: E/TiExceptionHandler(4025): ^
05-28 19:30:54.544: E/TiExceptionHandler(4025): Error: length=2; index=10
05-28 19:30:54.544: E/TiExceptionHandler(4025): at initCrashlytics (/ui/AppFrame.js:13802:13)
05-28 19:30:54.544: E/TiExceptionHandler(4025): at Titanium. (/ui/AppFrame.js:13865:27611)
05-28 19:30:54.544: E/TiExceptionHandler(4025): com.crashlytics.android.core.CrashTest.indexOutOfBounds(CrashTest.java:30)
05-28 19:30:54.544: E/TiExceptionHandler(4025): com.crashlytics.android.core.CrashlyticsCore.crash(CrashlyticsCore.java:622)
05-28 19:30:54.544: E/TiExceptionHandler(4025): com.crashlytics.android.Crashlytics.crash(Crashlytics.java:323)
05-28 19:30:54.544: E/TiExceptionHandler(4025): ti.crashlytics.TitaniumCrashlyticsModule.crash(TitaniumCrashlyticsModule.java:70)
05-28 19:30:54.544: E/TiExceptionHandler(4025): org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
05-28 19:30:54.544: E/TiExceptionHandler(4025): org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:55)
05-28 19:30:54.544: E/TiExceptionHandler(4025): org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:41)
05-28 19:30:54.544: E/TiExceptionHandler(4025): ti.modules.titanium.TitaniumModule$Timer.run(TitaniumModule.java:166)
05-28 19:30:54.544: E/TiExceptionHandler(4025): android.os.Handler.handleCallback(Handler.java:873)
05-28 19:30:54.544: E/TiExceptionHandler(4025): android.os.Handler.dispatchMessage(Handler.java:99)
05-28 19:30:54.544: E/V8Exception(4025): Exception occurred at /ui/AppFrame.js:13802: Uncaught Error: length=2; index=10

For android this is the same problem I had... narbs is correct with TiExceptionHandler capturing everything.
My workaround was to implement
Ti.App.addEventListener('uncaughtException',function(evt) {
Crashlytics.throwMyCustomException(evt.message,evt.line,evt.sourceName,evt.lineSource,evt.javascriptStack.toString());
}

@Kroll.method
public void throwMyCustomException(String message, String myline, String sourceNameAndroid, String lineSource, String javascriptStack)
{
Throwable barT = new Throwable(message);
String[] lines = javascriptStack.split("\r?\n");
int count = 1;
StackTraceElement[] stackTarray = new StackTraceElement[lines.length];

   	for (String lineStack : lines) {

	   	StackTraceElement stackNew = new StackTraceElement(sourceNameAndroid, lineStack, lineSource,  Integer.parseInt(myline));
	   	stackTarray[count-1] = stackNew;

   	}

	barT.setStackTrace(stackTarray);

	try {
		throw new RuntimeException(message, barT);
	} catch (RuntimeException e) {
		Crashlytics.logException(e);
	}
}

I created a PR for the module if you want to see what i did there

commented

@bubinf thank you - that really helped and worked well with a couple of bug fixes. I implemented this approach but sent the data as a dictionary - code below.

Also, the uncaughtException event can be trapped on iOS and Android but the event parameters are a little different - the code below handles different sources for the stack trace parameter.

Javascript:

function uncaughtExceptionListener(e) {

	var params = {
		message: e.message,
		line: e.line,
		sourceName: e.sourceName,
		lineSource: e.lineSource,
		javascriptStack: (e.javascriptStack != null ? e.javascriptStack.toString() : (e.stack != null ? e.stack.toString() : null))
	};

	if (crashlytics != null) {
		crashlytics.throwMyCustomException(params);
	}
}

Ti.App.addEventListener('uncaughtException', uncaughtExceptionListener);

Module method to throw custom exception when uncaughtException trapped:

@Kroll.method
public void throwMyCustomException(HashMap args) {

	if (args == null) {
		return;
	}
	
	KrollDict argsDict = new KrollDict(args);

	String message = argsDict.getString("message");
	String line = argsDict.getString("line");
	String sourceName = argsDict.getString("sourceName");
	String lineSource = argsDict.getString("lineSource");
	String javascriptStack = argsDict.getString("javascriptStack");

	Throwable barT = new Throwable(message);
	String[] lines = javascriptStack.split("\r?\n");
	
	int count = 0;
	StackTraceElement[] stackTarray = new StackTraceElement[lines.length];

	for (String lineStack : lines) {
		StackTraceElement stackNew = new StackTraceElement(sourceName, lineStack, lineSource, Integer.parseInt(line));
		stackTarray[count] = stackNew;
		count++;
	}

	barT.setStackTrace(stackTarray);

	try {
		throw new RuntimeException(message, barT);
	} catch (RuntimeException e) {
		Crashlytics.logException(e);
	}
}