bugsnag / bugsnag-flutter

BugSnag crash reporting for Flutter apps
https://docs.bugsnag.com/platforms/flutter/
MIT License
11 stars 11 forks source link

budgsnag.start #148

Closed cacothi closed 2 years ago

cacothi commented 2 years ago

Describe the bug

Hi Team,

I've simply followed the initial steps to add Bugsnag on my Flutter app and it didn't enable my app to start.

iOS: Error Details are attached below Android: No error is issued, but the app freezes on the launch screen

Steps to reproduce

as per steps on https://app.bugsnag.com/app/app/overview

  1. flutter pub add bugsnag_flutter
  2. add the following code
    
    import 'package:bugsnag_flutter/bugsnag_flutter.dart';

void main() => bugsnag.start( apiKey: 'KEY', runApp: () => runApp(const MyFlutterApp()), );

3. flutter run

### Environment

- Bugsnag version:
- Flutter version:
- Flutter-first app or native app with Flutter component(s):
- iOS/Android version:
- Simulator/emulator or physical device:

<!--
  Below are a few approaches you might take to communicate the issue, in
  descending order of awesomeness. Please choose one and feel free to delete
  the others from this template.
-->

### Flutter Doctor

[✓] Flutter (Channel stable, 3.0.3, on macOS 12.4 21F79 darwin-arm, locale en-AU) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.4.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.68.1) [✓] Connected device (5 available) [✓] HTTP Host Availability


### Code 

void main() async {

WidgetsFlutterBinding.ensureInitialized(); final settingsController = SettingsController(SettingsService()); await settingsController.loadSettings();

await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, );

return bugsnag.start( apiKey: Config.budgsnagKey, runApp: () => (MyApp( settingsController: settingsController, initialLink: initialLink )) ); }


### Error

<!-- Error messages, if any -->
<details><summary>Error messages:</summary>

Launching lib/main.dart on iPhone in debug mode... Automatically signing iOS for device deployment using specified development team in Xcode project: XXX CocoaPods' output: ↳ Preparing Analyzing dependencies Inspecting targets to integrate Using ARCHS setting to build architectures of target Pods-Runner: (``) Finding Podfile changes A bugsnag_flutter

ebelevics commented 2 years ago

Same my app just freezes, and I can't do anything about it. Have yet no idea why bugsnag start isn't called separately, otherwise if something fails whole app freezes

I had internet turned off, but that should not freeze the app, but let it though

D/Bugsnag ( 9749): Loaded: LastRunInfo(consecutiveLaunchCrashes=0, crashed=false, crashedDuringLaunch=false)
D/Bugsnag ( 9749): Persisted: consecutiveLaunchCrashes=0
D/Bugsnag ( 9749): crashed=false
D/Bugsnag ( 9749): crashedDuringLaunch=false
D/Bugsnag ( 9749): Plugin 'com.bugsnag.android.BugsnagReactNativePlugin' is not on the classpath - functionality will not be enabled.
W/BugsnagNDK( 9749): Initialization complete!
I/Bugsnag ( 9749): Initialised NDK Plugin
I/Bugsnag ( 9749): Initialised ANR Plugin
D/Bugsnag ( 9749): No startupcrash events to flush to Bugsnag.
D/Bugsnag ( 9749): No regular events to flush to Bugsnag.
D/Bugsnag ( 9749): Bugsnag loaded

D/Bugsnag ( 6931): SessionTracker#flushStoredSession() - attempting delivery
I/Bugsnag ( 6931): Session API request finished with status UNDELIVERED
W/Bugsnag ( 6931): Leaving session payload for future delivery
D/Bugsnag ( 6931): SessionTracker#flushStoredSession() - attempting delivery
I/Bugsnag ( 6931): Session API request finished with status UNDELIVERED
W/Bugsnag ( 6931): Leaving session payload for future delivery
D/Bugsnag ( 6931): SessionTracker#trackSessionIfNeeded() - session captured by Client
D/Bugsnag ( 6931): SessionTracker#trackSessionIfNeeded() - attempting initial delivery
I/Bugsnag ( 6931): Session API request finished with status UNDELIVERED`_

it does work on Android when i-net is turned on, but doesn't when off

johnkiely1 commented 2 years ago

Hi @cacothi.

This looks like it is likely a known dependency issue when using Cocoapods and M1 architecture.

There appears to be some similar errors encountered : https://stackoverflow.com/questions/71815618/swift-cocoa-pods-issue-library-ruby-gems-2-6-0-gems-ffi-1-15-5-lib-ffi-c-bund

This suggests doing the following:

sudo arch -x86_64 gem install ffi

Then

arch -x86_64 pod install

The other suggestion would be to update your version of Ruby to >2.7.0

johnkiely1 commented 2 years ago

Hi @ebelevics, are you also seeing the freezing issue on Android or also on iOS?

ebelevics commented 2 years ago

On Android physical device. On iOS can't test it as internet is required to verify the build on phone. I also tried to use try-catch bugsnag.start in order to bypass it, but no luck

P.S. tried running those command line, but did do a trick

ebelevics commented 2 years ago

Ok, for some reason now it did passed through on Android device without internet, with same messages as stated above. Even tho the code remained almost the same.

ebelevics commented 2 years ago

I'll just add this, maybe it might help. But it's the code that did not worked before, after some while now works.

  bugsnag.start(
    apiKey: Platform.isAndroid
        ? FlutterConfig.get(BUGSNAG_ANDROID_API_ENV_KEY)
        : FlutterConfig.get(BUGSNAG_IOS_API_ENV_KEY),
    releaseStage: "release",

    // onError callbacks can be used to modify or reject certain events
    runApp: () async {
      //--SETUP--//
      await setup();
      await mainContainer.read(authProvider.notifier).getUser();

      runApp(
        UncontrolledProviderScope(
          container: mainContainer,
          child: const MainApp(),
        ),
      );
    },
    onError: [(event) => kReleaseMode],
  );
johnkiely1 commented 2 years ago

OK, it seems a little unusual if no code changes were made, but now works. Can you walk me through the exact steps you are taking?

It may be worth mentioning that sessions would be sent separate to error events. The logs above look like we are trying to send through session information but failing due to the lack of internet. These should then be stored on the device and sent when an internet connection is restored. If you are able to reproduce the issue consistently, it might be interesting to see what happens if you were to turn off the session capture temporarily. https://docs.bugsnag.com/platforms/flutter/configuration-options/#auto-track-sessions and repeat the steps. It could help narrow down if there is a connection between the issue you are seeing and the session information delivery when internet connectivity is restored.

ebelevics commented 2 years ago

Ok, I'll let you know if I'll be able to reproduce this issue on consistent basis

johnkiely1 commented 2 years ago

HI @ebelevics, just checking in to see if you've been able to reproduce? I'm going to close this for now but happy to reopen if there is any further information you can share.