From 9e7630d7998b22af3e9920dc21011b988ec0bd07 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos <6349682+vaind@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:29:53 +0100 Subject: [PATCH] fix: linux crashpad handler path (#2443) --- flutter/lib/src/native/c/sentry_native.dart | 19 ++++++++++++++++++- flutter/pubspec.yaml | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/flutter/lib/src/native/c/sentry_native.dart b/flutter/lib/src/native/c/sentry_native.dart index 9e2b8d51f6..d9fa5a971e 100644 --- a/flutter/lib/src/native/c/sentry_native.dart +++ b/flutter/lib/src/native/c/sentry_native.dart @@ -3,6 +3,7 @@ import 'dart:ffi'; import 'dart:io'; import 'dart:typed_data'; +import 'package:collection/collection.dart'; import 'package:ffi/ffi.dart'; import 'package:meta/meta.dart'; @@ -31,7 +32,7 @@ class SentryNative with SentryNativeSafeInvoker implements SentryNativeBinding { static String dynamicLibraryDirectory = ''; @visibleForTesting - static String? crashpadPath; + static String? crashpadPath = _getDefaultCrashpadPath(); SentryNative(this.options); @@ -396,3 +397,19 @@ extension on List { return cObject; } } + +String? _getDefaultCrashpadPath() { + if (Platform.isLinux) { + final lastSeparator = + Platform.resolvedExecutable.lastIndexOf(Platform.pathSeparator); + if (lastSeparator >= 0) { + final appDir = Platform.resolvedExecutable.substring(0, lastSeparator); + final candidates = [ + '$appDir${Platform.pathSeparator}crashpad_handler', + '$appDir${Platform.pathSeparator}bin/crashpad_handler' + ]; + return candidates.firstWhereOrNull((path) => File(path).existsSync()); + } + } + return null; +} diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index beb156421c..d89d1c7c1c 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -28,6 +28,7 @@ dependencies: meta: ^1.3.0 ffi: ^2.0.0 file: '>=6.1.4' + collection: ^1.16.0 dev_dependencies: build_runner: ^2.4.2 @@ -36,7 +37,6 @@ dev_dependencies: mockito: ^5.1.0 yaml: ^3.1.0 # needed for version match (code and pubspec) flutter_lints: '>=4.0.0' - collection: ^1.16.0 remove_from_coverage: ^2.0.0 flutter_localizations: sdk: flutter