Xamarin.Forms log exception when App crashes in Android - exception

Right now I have a Try Catch in Main.cs for iOS, where I'm logging the exception if the App crashes.
What is the equivalent in Android?
I've seen a lot of posts here and Xamarin Forums about event handlers in MainActivity, but those don't seem to work at all. Example:
AndroidEnvironment.UnhandledExceptionRaiser += HandleAndroidException;
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += HandleExceptions;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
I have the methods for each, and they never get called.

Related

Autodesk Forge Design Automation Freeze

We are running an application using Forge Design Automation for Revit and have an issue I can't fully explain. Our tests have been working just fine but we got a couple lately that seem to freeze inside Revit as far as I can tell. Here is the OnStartup method of my external application:
public ExternalDBApplicationResult OnStartup(ControlledApplication application)
{
SharedData.Initialize(new LoggerConsole());
// Startup is only for registering the DA ready event
SharedData.Log.AddLine("Design automation startup in App");
DesignAutomationBridge.DesignAutomationReadyEvent += DesignAutomationBridge_DesignAutomationReadyEvent;
SharedData.Log.AddLine("Design automation event registered");
return ExternalDBApplicationResult.Succeeded;
}
Here is the outline of the event handler referenced:
void DesignAutomationBridge_DesignAutomationReadyEvent(object sender, DesignAutomationReadyEventArgs e)
{
// Start the actual processing here
SharedData.Log.AddLine($"Into automation ready event, working directory is: {Environment.CurrentDirectory}");
...Other Code...
}
The log for one of the jobs I'm talking about (clipped to relevant portion) looks as follows:
[12/10/2020 01:34:42] Design automation startup in App
[12/10/2020 01:34:42] Design automation event registered
[12/10/2020 01:34:42] Initialize and get RCE: (VersionBuild) 21.1.10.26 (VersionNumber) 2021 (SubVersionNumber) 2021.2
[12/10/2020 04:34:33] Error: Revit Core Engine Core Console is shut down due to process time limit.
[12/10/2020 04:34:33] End script phase.
As you can see, it makes it to the log line about event registered so the only thing left to do after that is return success. It does seem to get that success because the next log line is from inside Revit (the one that starts with 'Initialize and get'). Then after that it seems to wait 3 hours and then error because of time out. It never logs the very first line of the event handler so as far as I can tell that's not getting called.
Anyone else experienced this? How would you even go about debugging it?

Wait for App to idle after Interruption

I have a ViewController that will request access to location services on init via
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
[_locationManager requestWhenInUseAuthorization];
}
This triggers the "Allow app to access your location while you use the app?"-alert.
I use [self addUIInterruptionMonitorWithDescription:handler:] to react to this. I am encountering the following problem: after dismissing the request-dialog, the ui-test does not continue. The alert is dismissed, but Xcode waits for the app to become idle, but it looks like the app is idle:
t = 67.35s Wait for app to idle
The test fails, because the app is stuck here. If i tap into the simulator, Xcode logs.
t = 72.27s Synthesize event
and continues the test.
Is there a reason, why Xcode tries to wait for the app? A workaround seems to be to tell Xcode that the UI changed or an event happened. Is there a way to trigger this?
After presenting the alert you must interact with the interface. This is a known bug with Xcode 7.2. Simply tapping the app works just fine, but is required.
addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
alert.buttons["Allow"].tap()
return true
}
app.buttons["Find Games Nearby?"].tap()
app.tap() // need to interact with the app for the handler to fire
XCTAssert(app.staticTexts["Authorized"].exists)
See my blog post for more information.

how to debug wp8 app downloaded from store?

I've made a game using marmalade sdk and AppEasy engine and it works when I test it on the device but after submitting to store and downloading it only shows splash screen and then terminates.
Is there a way to debug it? Android and ios both have tools to trace the console output, is there such a tool for wp8? I only found how to do that for apps deployed to the device locally but no way to debug downloaded apps :(
For my other game made in same framework (with same issue) there is a crash report on the dev center dashboard with error saying 'STACK_OVERFLOW_DATA' but that doesn't help much
also tried this (solution found in some other question):
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
string result = "nothing :(";
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists("iwtrace.txt"))
{
using (var stream = new IsolatedStorageFileStream("iwtrace.txt", FileMode.Open, store))
{
using (var fileReader = new StreamReader(stream))
{
result = fileReader.ReadToEnd();
}
}
}
EmailComposeTask task = new EmailComposeTask();
task.To = "";
task.Subject = "crash log " + e.ExceptionObject.Message;
task.Body = result;
task.Show();
}
but it never get's to showing the email form
There's no way yet to debug retail version of WP8 apps especially which are made in Marmalade.
You can read more about that in the article explaining how to test the retail version.
According to the article you need to test the retail version via Visual Studio in case of Native C# app. I suppose even native XAML apps can't be debugged after downloading from store.
I've asked almost similar question on Marmalade forums last year. The only way at that time was to use Windows Power tool or Visual Studio.
To test the function, run your code from Visual Studio in release mode and see if it crashes or not. That's the only thing you can do in this case as far as I know.

Libgdx AndroidApplication native(?) crash

I have a strange problem. I use a nightly from last week. If I recall correctly it's from 23/3.
What happens is that I run a Libgdx Activity and it runs fine. Than I finish the app. I start the libgdx activity again and it crashes... This happens a lot but not all the time.
In debug mode it doesn't happen at all. Any ideas? It doesn't print any crash log but I think it has something to do with this log: http://pastebin.com/3BFrjbES
My code doesn't do any thing special right now. It's just printing the FPS in a stage....
I think there is an error in the log that may be connected: EGL error: EGL_BAD_CONTEXT.
This is printed just before the previous log.
Thanks.
What does "finish the app" mean? A pause (pressing home) or a destroy?
I wonder if it is any way related to LibGDX attempting to preserve the EGL Context. The default for Android is to not preserve it but LibGDX attempts to enable it if you are on SDK >= 11. You could try to disable preservation in your AndroidApplication subclass by doing something like:
View view = ((AndroidGraphics)Gdx.graphics).getView();
try {
Method method = null;
for (Method m : view.getClass().getMethods()) {
if (m.getName().equals("setPreserveEGLContextOnPause")) {
method = m;
break;
}
}
if (method != null) {
method.invoke((GLSurfaceView20)view, false);
}
} catch (Exception e) {
}
I found out the problem. The problem disappeared after I removed hardwareAccelaration="true" from my application tag in the manifest. I don't know why it matters as my device is 4.0.4 which means that it's enabled by default.

Getting AIR stacktraces in ipad for release build [duplicate]

I'm trying to debug an issue on a clients machine. The problem is that the problem is a runtime error with very little clue as to where it is. It is an intermittent problem. I know ADL allows me to run the application in a debug mode. The problem is that to tell the user to download and manage the ADL invokation is going to be very difficult. It would be a lot easier if I could just give the end user one install/executable to install and run and then send me the trace of the issue. So what I'm looking for is easy steps for the client to be able to run the AIR app in debug mode. Downloading ADL and finding the install location of the app is going to be difficult to manage remotely with the end user.
Update:
You have to make sure you are working with AIR 3.5 and Flash 11.5 and also include the following flag "-swf-version=18" in additional compiler settings. You then have to catch the global error as mentioned in the answer and it will show you the location of the error. No line numbers of course. Just routine names. Thanks a milion to Lee for the awsome answer.
not a direct answer but if you publish for AIR3.5 (or 3.6 beta), you can get some debug info:
add a listener for uncaught RTEs to top level of your app:
this.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, globalErrorHandler);
and grab debug info from error in listener:
function globalErrorHandler(event:UncaughtErrorEvent):void
{
var message:String;
//check for runtime error
if (event.error is Error)
message = (event.error as Error).getStackTrace();
//handle other errors
else if (event.error is ErrorEvent)
message = (event.error as ErrorEvent).text;
else
message = event.error.toString();
//do something with message (eg display it in textfield)
myTextfield.text = message;
}
getStackTrace will return a stack trace even for release AIR apps (as long as you use AIR3.5 or above).
Without the SDK Tools; I don't think it is possible to run an aIR app in debug mode. But, here are a few alternatives to consider:
The client must have some idea what is going on to cause the error, right? Can you give them a special build with Alert Boxes or logging or something to help isolate the error to a line of code?
Can you listen for the uncaughtException event? The event will give you the full stack trace ( Error.getStackTrace() ); which you could then log--possibly with other information. Then you just have to tell your client to "Go here" and "send me this file." Or even display the info in some Alert and have the user copy and paste it into an email to you. More info on uncaughtException here and here
check my post. Maybe it helps you to get stack trace with line numbers in a AIR release build.
How can I get stacktrace for Adobe AIR global runtime errors in non-debug mode?
I use it in 2 big projects right now and it works very well.
Greetings