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?
Asked
Active
Viewed 654 times
0
-
There is an ios and android folder in evert flutter project – Jun 15 '21 at 10:53
-
1Yes @YouriLieverdink , but when we create a flutter module, these folder are Generated folders which are not be source controlled, and also they have mentioned in the doc as to not make any changes in these folders as the changes might be overwritten by flutter – ParasGarg Jun 15 '21 at 11:00
-
Could you provide a link to where this is mentioned? – Jun 15 '21 at 11:32
-
https://flutter.dev/docs/development/add-to-app/ios/project-setup#module-organization Read the note here, same for Android – ParasGarg Jun 15 '21 at 11:33
-
Oh my mistake. The only thing I can think of is to implement Crashlytics for both iOS and Android separately. – Jun 15 '21 at 12:35
-
That is already there, but how can I assure that any crash which happens inside flutter module is caught on Firebase? – ParasGarg Jun 15 '21 at 12:39
-
You can add this line to your main function to record all uncaught flutter errors. // FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError; – Jun 15 '21 at 13:00
-
To even include firebase, the changes have to be made to the iOS and Android folders, but doing so is not recommended. – ParasGarg Jun 16 '21 at 03:49
1 Answers
0
I had the same issue.
I solved by this way:
- Don't put changes in ios and android folder.
- Use callback to send your crash information by the native side.
- 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.