I want to add a flutter app into my existing native app, which I am able to do succesfully using flutter docs. After this, I want to log crashes and other data using firebase for the flutter screens. Since normal implementation of Flutter Fire requires changes to be made in the android and iOS folders, but these folders do not exist in flutter project. So any ideas on how to do it?

1

There are 1 best solutions below

1
On

I had the same issue.

I solved by this way:

  1. Don't put changes in ios and android folder.
  2. Use callback to send your crash information by the native side.
  3. Configure FarebaseCrashlytics only in native app.

For example:

Native side in Swift:

let methodChannel = FlutterMethodChannel(name: "FLUTTER_CHANNEL", binaryMessenger: flutterEngine.binaryMessenger)
                methodChannel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
                    if call.method == "HANDLE_ERROR" {
                        let userInfo: [String: String] = [
                            "deviceId": UIDevice.current.identifierForVendor!.uuidString
                        ]
                        var errorData = "";
                        if let args = call.arguments as? Dictionary<String, Any> {
                            errorData = args["data"] as? String ?? ""
                        }

                        let error = NSError(domain: errorData, code: 0, userInfo: userInfo)

                        Crashlytics.crashlytics().record(error: error)
                    }
                }

Flutter side:

   Future<void> _handleErrorNative([String errorData]) async {
    try {
      final methodChannel = MethodChannel("FLUTTER_CHANNEL");
      await methodChannel.invokeMethod(
        'HANDLE_ERROR',
        {
          "data": errorData,
        },
      );
    } on PlatformException catch (_) {
      print("_handleErrorNative PlatformException");
    }
  }

Remember, the crash only will send after reopen the app.