microsoft / appcenter-sdk-react-native

Development repository for the App Center SDK for React Native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash attachments not working in React Native Android

Sergey-Nosov-CloudFit opened this issue · comments

Description

Experiencing the same issue as in #245
However, it is not exactly clear how the poster in that issue fixed his/her problem.

It seems that the fix was setting:
<string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">ALWAYS_SEND</string>
But in my case doing that prevents crash reporting all together rather than fixing attachments.

Limitations do not list React Native as a platform available for Attachments. Are Attachments no longer available in React Native as described in the following link?
https://learn.microsoft.com/en-us/appcenter/sdk/crashes/react-native#add-attachments-to-a-crash-report

Repro Steps

Please list the steps used to reproduce your issue.

  1. Configure Crashes listener as follows
  await Crashes.setListener({
    onBeforeSending: (report: ErrorReport) => {
      Alert.alert('after Crashes.process and before sending the crash. ' + report);
    },
    onSendingFailed: (report: ErrorReport) => {
      Alert.alert('crash report could not be sent. ' + report);
    },
    onSendingSucceeded: (report: ErrorReport) => {
      Alert.alert('crash report sent successfully. ' + report);
    },
    getErrorAttachments: (_reports: ErrorReport) => {
      return (async () => {
        const testAttachment = ErrorAttachmentLog.attachmentWithText('Hello text attachment!', 'hello.txt');
        return [testAttachment];
      })();
    }
  });
  1. Observe onBeforeSending and onSendingSucceeded events firing successfully.
  2. Observe the Crash reported in the App Center; however the attachment is missing and the attachments tab reporting:
    With the App Center SDK, you can attach custom data to your reports so that you can better understand the context of when your app crashed. Follow the [SDK instructions](https://docs.microsoft.com/en-us/mobile-center/sdk/crashes/react-native) to learn how to pass variables or attach files to your report.

Details

  1. Which version of the App Center SDK are you using?
    4.4.5
  2. Which OS version did you experience the issue on?
    Android 9.0 (Pie) - API 28
  3. What device version did you see this error on? Were you using an emulator or a physical device?
    Emulator 32.1.11-9536276
  4. What third party libraries are you using?
    Various
  5. Run the following command and paste the output below: react-native info
info 
  React Native Environment Info:
    System:
      OS: Windows 10
      CPU: (12) x64 Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz
      Memory: 12.07 GB / 31.73 GB
    Binaries:
      npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD

Thank you!

Hi @Sergey-Nosov-CloudFit , thank you for reporting this. We are investigating this issue and will get back to you as soon as possible.

Hi @Sergey-Nosov-CloudFit , may I ask if you have this set in your configuration to ASK_JAVA_SCRIPT as per the below:
Open the project's android/app/src/main/res/values/strings.xml file and verify that appCenterCrashes_whenToSendCrashes is set to ASK_JAVASCRIPT. ASK_JAVASCRIPT

Hello, here are the settings as we have them currently:

    <string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">DO_NOT_ASK_JAVASCRIPT</string>
    <string name="appCenterAnalytics_whenToEnableAnalytics" moduleConfig="true" translatable="false">ALWAYS_SEND</string>

The crash repots do flow-in to AppCenter. It is just the attachments that are missing. If the appCenterCrashes_whenToSendCrashes setting was incorrect the reports would not flow in at all, right? Or is there more to it?

Thank you!

Regardless of the post above, I just tried changing the appCenterCrashes_whenToSendCrashes setting from DO_NOT_ASK_JAVASCRIPT to ASK_JAVASCRIPT and adding the following line of code:

Crashes.notifyUserConfirmation(UserConfirmation.ALWAYS_SEND);

This application gets deployed to company-owned devices, and needs no user consent.

Unfortunately, this did not fix the issue -- attachments are still missing.

Hi @Sergey-Nosov-CloudFit , thank you for the further information. May I ask about the size of the attachment you're trying to send? It should not exceed 1.4 MB on Android.

The attachment is 'Hello text attachment!' -- 22 bytes. Thanks!

Hello @Sergey-Nosov-CloudFit, could you please share a sample application where the issue is reproducible?
It will be very helpful for us.

Sure, here is a sample application that demonstrates the issue:
https://github.com/orderfactory/react-native-app-center

Thanks!

Thank you @Sergey-Nosov-CloudFit, for the application you provided.
I confirm that there is an issue with provided example. But I need some more time to look into it deeper.

commented

Hi @Sergey-Nosov-CloudFit , this definitely looks like a bug.

As a workaround using ASK_JAVASCRIPT for appCenterCrashes_whenToSendCrashes should work.
You can skip implementation of shouldAwaitUserConfirmation, and the crash will be sent automatically. But if you do implement, and return true, then you will need to call Crashes.notifyUserConfirmation manually. This worked for me on your app.
You mentioned that this option didn't work for you. May I ask you to double check and if it is still not working, please add the line AppCenter.setLogLevel(LogLevel.VERBOSE); and share the app logs.

@DmitriyKirakosyan, thank you for the workaround. Yep, it works!

It did not work for me two weeks ago as I did both, changed the appCenterCrashes_whenToSendCrashes setting from DO_NOT_ASK_JAVASCRIPT to ASK_JAVASCRIPT and added the following line of code:

Crashes.notifyUserConfirmation(UserConfirmation.ALWAYS_SEND);

Setting 'ASK_JAVASCRIPT' but not Crashes.notifyUserConfirmation(UserConfirmation.ALWAYS_SEND); works.

This is super confusing.

commented

I'm going to close this issue because we don't have immediate plans to fix it, but we appreciate contributions!