displaying runtime errors in android/ios installed app - android

I've been trying to get errors to display in a text field within the app for ease of error reporting from users.
I've had some success using this code I found on stackoverflow. It's used at the top level of the app but it's not working on device:
//start code
this.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, errorHandler);
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;
}
//end code
At first this wouldn't work on the device and I thought it was because upon the error, when developing on the pc, flashplayer would display the actionscript popup with the error. Which you would need to click "dismiss all" or close and then the globalErrorHandler was called after and then the error written to the textfield. I thought this is what was keeping it from showing up on the device. However, by adding event.preventDefault() I was able to suppress the actionscript popup when developing on the desktop and the error was written to the textfield successfully. This was not the case however on the andriod device. It still just hangs on the error. It's as if the default error event cannot be suppressed on android.
Thanks for your time. Any help appreciated!
EDIT 22/09/2017: I was able to see the error on device finally. It had to do with while on desktop publishing the error would be shown. However, on device the behavior was different and something was covering the textfield, by bring it to the front on error I was able to see it. However, I still see that some errors deeper in the class hierarchy are not being caught.

In our project we have it simpler (and it is working):
stage.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
private function onUncaughtError(e:UncaughtErrorEvent):void
{
// Console is basically a TextField for debug/diagnosis output.
if (e.error) Console.error(e.error.getStackTrace());
e.preventDefault();
}
The other thing you should probably check is whether your TextField actually displays any text at all for there might be text embedding issues, unrelated to the error handling routine.
UPD: Loading SWFs so it doesn't mix with the parent.
var request:URLRequest = new URLRequest(path);
var context:LoaderContext = new LoaderContext;
context.applicationDomain = ApplicationDomain.currentDomain;
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.load(request, context);

Related

React Native Expo Android crashes only in production and is also not catchable in Sentry

Already tried to look into all different problems here on StackOverflow with related titles, like this one. But no success.
Here is the piece of code where the problem happens:
const fetchApi = useCallback(async () => {
setIsLoading(true);
if (activePortfolioId) {
try {
const response = await getApis().portfoliosApi.getPortfolioOverviewById(
activePortfolioId
);
if (response.data && response.data?.tickers?.length) {
setItems(handleListItems(response.data.tickers));
}
} catch (error) {
Sentry.Native.captureException(error);
Sentry.Native.captureMessage('HELLO?');
Alert.alert(
'Sorry!',
'We were unable to retrieve the performance list. Please try again later.'
);
} finally {
setIsLoading(false);
}
}
}, [activePortfolioId]);
So what happens is, on iOS I have no problem at all here, either on DEV or PROD, using real device or simulator, everything works fine, never went to the catch statement. On Android, using simulator or real device with Expo, it's all fine too, even using expo start --no-dev --minify to try to reproduce the app as PROD, occurs no errors at all. I have tried everything that came on my mind, like removing pieces of the code to see if the problem stops. Like instead of calling the API, just setting the items, like this:
setItems(handleListItems(response.data.tickers)); because I also thought that the problem might be with my handler function, I also tried to just do setItems([{ OBJECT HERE }]);. The problem has just stopped once I stopped setting the items. So I also tried to check my renderItem function, tried to stop using any styled component, just what React Native provides, nothing works. Then I decided to bring Sentry to my code but even with Sentry, no issues is shown there. I open the screen, it is loading, fetches the API, then it falls in the catch block, because I see the Alert on Android and then the app crashes and go back to the splash screen frozen. The only issue that appeared on Sentry was:
Could not open URL 'https://XXXXXXX': No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://XXXXXXX... flg=0x10000000 }
But strangely I have never clicked on this during the "tests" and this link just appears on the login screen, shouldn't have anything to do with the problem itself, right?
I really don't know what else I could try to do and figure out what is causing this problem, so decided to ask for help and maybe find someone who already went through something similar.
Thanks!
PS: I'm using TS too, so apparently no problems with some possible undefined or whatever.
Found the issue, it was with the Intl. Solution here.

OnReceiveContentListener showing "AppName doesn't support image insertion here"

When using the OnReceiveContentListener I followed along with the guide here. I also looked at the example project they reference. From my understanding the way it works is that if I enter the code
val editTextOnReceiveContentListener =
androidx.core.view.OnReceiveContentListener { editText, contentInfoCompat ->
val split = contentInfoCompat.partition { it.uri != null }
val uriContent = split.first
val remaining = split.second
/** Process uriContent here... **/
//return remaining
remaining
}
ViewCompat.setOnReceiveContentListener(
myEditText,
arrayOf("image/gif", "image/png"),
editTextOnReceiveContentListener
)
Then when 'remaining' is null the app will NOT show the user "AppName doesn't support image insertion here". And most of the time it seems to be work just as I expect.
However if I use the 'Cold Boot Now' option for starting the emulator (and other times occasionally) then the first gif that is entered will still display that image insertion is not supported here. Everything else seems to work fine except it shows the error. This happens even though the log shows that 'remaining' is null. I tested it on emulator devices Nexus 5 and Pixel 2 for API 29 and 31.
My question is, is this something that I should be concerned about and/or can fix in some way?

Android printing with Brother SDK via WiFi throws ERROR_WRONG_LABEL despite selecting correct labelNameIndex

I've been trying to print with Brother Print SDK 3.5.1 on Android 8.1.0. I keep getting ERROR_WRONG_LABEL.
This is the code I use
void printPdf() {
// Specify printer
final Printer printer = new Printer();
PrinterInfo settings = printer.getPrinterInfo();
settings.printerModel = PrinterInfo.Model.QL_810W;
settings.port = PrinterInfo.Port.NET;
settings.ipAddress = "192.168.1.73";
settings.workPath = "storage/emulated/0/Download/";
// Print Settings
settings.labelNameIndex = LabelInfo.QL700.W62RB.ordinal();
settings.printMode = PrinterInfo.PrintMode.FIT_TO_PAGE;
settings.orientation = PrinterInfo.Orientation.PORTRAIT;
settings.isAutoCut = true;
printer.setPrinterInfo(settings);
// Connect, then print
new Thread(new Runnable() {
#Override
public void run() {
if (printer.startCommunication()) {
PrinterStatus result = printer.printPdfFile("/storage/emulated/0/Download/hello world red.pdf", 1);
if (result.errorCode != PrinterInfo.ErrorCode.ERROR_NONE) {
Log.d("TAG", "ERROR - " + result.errorCode);
}
printer.endCommunication();
}
}
}).start();
}
My printer model is QL-810W and I use the black and red W62 roll.
I've tried the Sample Application, where setting W62RB in labelNameIndex prints fine.
Changing the roll for different one with different width didn't help.
I've also tried iterating over numbers 0 to 50 and using them as labelNameIndex.
Based on this thread, I thought that the issue may be in specifying the workPath attribute. Setting workPath to getContext().getCacheDir().getPath() results in ERROR_OUT_OF_MEMORY instead of ERROR_WRONG_LABEL. Not specifying workPath and adding <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> to AndroidManifest.xml results in ERROR_WRONG_LABEL
EDIT
I've modified the Brother Sample app and uploaded it to GitHub. The app now launches Activity_PrintPdf.java by default where I inserted my printing code with hardcoded values at the beginning of onCreate method - this works fine and prints the PDF file as expected.
Then I created a new Empty Activity project in Android Studio, copy pasted the library, added the imports to build.gradle and copy pasted the permissions into AndroidManifest.xml. Then I copy pasted the printing code at the beginning of onCreate method in MainActivity.java. Running the app results in ERROR_WRONG_LABEL.
This is the modified working example app and this is the one that results in the error. I want to use the code as native module that I call from my React Native app, so it's important that I manage to set up the printing code from scratch rather than modifying the existing example app.
EDIT 2
I've inspected the library with a debugger: when executing printer.setPrinterInfo(mPrinterInfo) the library internally calls private boolean createWorkPath(String dirPath) of Printer object. On return from this method, the debugger shows Source code doesn't match the bytecode and seems to forget the created directory. This also internally sets mResult.errorCode = ErrorCode.ERROR_WORKPATH_NOT_SET. However, instead of rising any error here the code just silently proceeds, which later results in ERROR_WRONG_LABEL when trying to print. Running the same code snipper in the modified Sample app works fine.
I'd be grateful if you could help or suggest what to try next.
Thank you!
I've now fixed the issue, which was that the Brother library silently failed to create a temporarily folder and instead of reporting an error, it continued and failed later to read the label information. Based on this thread, it is now required to specify runtime file read and write permissions as opposed to the compile-time ones in AndroidManifest.xml.
Adding
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
at the beginning of onCreate before the printing code fixed the issue.

How to trigger / debug backdoor functionality in Xamarin.Forms.UITesting?

I'm trying to add a BackdoorMethod to a Xamarin.Forms application to bypass the login (IDP - opened in chrome browser) step. I have the feeling that the method is not getting triggered, but not sure, and I don't know how could I make sure about it.
I've read the documentation here: https://learn.microsoft.com/en-us/appcenter/test-cloud/uitest/working-with-backdoors
Check this thread: https://forums.xamarin.com/discussion/85821/xamarin-uitest-backdoor-on-droid-with-splash-screen-how-do-i-access-my-mainactivity
Checked this example: https://github.com/brminnick/UITestSampleApp/tree/master/Src
In the MainActivity.cs file I've defined the BackdoorMethod:
[Preserve, Export(nameof(BypassLoginScreen))]
public string BypassLoginScreen()
{
// some additional code here. the code is working, when I called it
// directly from OnCreate it was executed without any error
return "called";
}
From the test case i'm trying to invoke it like:
public constructorMethod(Platform platform)
{
this.platform = platform;
app = AppInitializer.StartApp(platform);
var result = app.Invoke("BypassLoginScreen"); // result == "<VOID>"
}
I'm not getting any error message, the method simply not called, or not returns anything. (or i don't know what's happening there with it, because breakpoint also not working as the app started from the device)
This should be already working. I have similar code and it works for me.
you can add inside your function
Android.Util.Log.WriteLine(Android.Util.LogPriority.Info, "BypassLoginScreen", $"Some text as info");
And observe the result in Device Logs, Filter by BypassLoginScreen to see if there is any log created with the tag BypassLoginScreen

Android application not crashing when it should [ACRA]

Hi all,
I'm using (trying at the moment) ACRA for bug-reporting. Scenario is:
I open the app: ACRA outputs ACRA is enabled for mypackage, intializing...
I enter the Settings (where I prepared a NullpointerException)
The app freezes and Preparing crash dialog is output via a toast
The app does not close, but instead outputs the same toast again and again (all Views are gone)
When I close the app, after a few seconds (of gathering data I guess) the crash dialog opens
I have the following Annotation in front of my Application subclass:
#ReportsCrashes(formKey = "iwontshowyoumyformkey", customReportContent = {
REPORT_ID, APP_VERSION_CODE, ANDROID_VERSION, PHONE_MODEL, BRAND,
STACK_TRACE },
mode = ReportingInteractionMode.DIALOG,
resToastText = R.string.acra_toast_text,
resDialogText = R.string.acra_dialog_text,
resDialogTitle = R.string.acra_dialog_title,
resDialogCommentPrompt = R.string.acra_dialog_comment_prompt,
resDialogOkToast = R.string.acra_dialog_ok_toast,
forceCloseDialogAfterToast=true)
A notable detail is that the error occurs again and again, according to the Logcat.
This made me think that the activity is restarted all the time, and the error is in onCreate...
But the fact that the tag is ACRA made me unsure if it isnt ACRA, reoutputting the error.
Problem: The app should be crashed and closed so that the dialog can appear, but isn't.
Question: How would I go about debugging/solving this? A solution would be even better...
Thank you in advance,
Till
It's not solved, but I decided to not spend any more time on it, and abandon ACRA.
Crittercism has proven to be quite painless.

Categories

Resources