Skip to content

Commit 52603c5

Browse files
authored
fix: Fix stripped categories in static frameworks (#6125)
* fix: Fix stripped categories in static frameworks * PR comments * lint
1 parent d50a587 commit 52603c5

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Fix crash in Session Replay when opening the camera UI on iOS 26+ by skipping redaction of internal views.
88
This may result in more of the camera screen being redacted. (#6045)
9+
- Fix crash in SentryDependencyContainer init when using the SDK as a static framework (#6125)
910

1011
## 8.56.0-alpha.1
1112

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@
10531053
FA6555142E30181B009917BC /* SentrySDKInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = FA6555132E30181B009917BC /* SentrySDKInternal.h */; };
10541054
FA6555162E30182B009917BC /* SentrySDKInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = FA6555152E30182B009917BC /* SentrySDKInternal.m */; };
10551055
FA65551A2E3018A3009917BC /* SentrySDKTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6555192E30189E009917BC /* SentrySDKTests.swift */; };
1056-
FA66143A2E4B593900657755 /* SentryApplication+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6614392E4B593000657755 /* SentryApplication+UIKit.swift */; };
1056+
FA66143A2E4B593900657755 /* SentryApplicationExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6614392E4B593000657755 /* SentryApplicationExtensions.swift */; };
10571057
FA6614FC2E4B8E1A00657755 /* TestSentryUIApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6614FB2E4B8E1500657755 /* TestSentryUIApplication.swift */; };
10581058
FA6615052E4BA4D700657755 /* ThreadSafeApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6615042E4BA4D200657755 /* ThreadSafeApplication.swift */; };
10591059
FA67DCC12DDBD4C800896B02 /* SentrySDKLog+Configure.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCC02DDBD4C800896B02 /* SentrySDKLog+Configure.swift */; };
@@ -2401,7 +2401,7 @@
24012401
FA6555132E30181B009917BC /* SentrySDKInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySDKInternal.h; path = include/SentrySDKInternal.h; sourceTree = "<group>"; };
24022402
FA6555152E30182B009917BC /* SentrySDKInternal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySDKInternal.m; sourceTree = "<group>"; };
24032403
FA6555192E30189E009917BC /* SentrySDKTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySDKTests.swift; sourceTree = "<group>"; };
2404-
FA6614392E4B593000657755 /* SentryApplication+UIKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryApplication+UIKit.swift"; sourceTree = "<group>"; };
2404+
FA6614392E4B593000657755 /* SentryApplicationExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryApplicationExtensions.swift; sourceTree = "<group>"; };
24052405
FA6614FB2E4B8E1500657755 /* TestSentryUIApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryUIApplication.swift; sourceTree = "<group>"; };
24062406
FA6615042E4BA4D200657755 /* ThreadSafeApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadSafeApplication.swift; sourceTree = "<group>"; };
24072407
FA67DCC02DDBD4C800896B02 /* SentrySDKLog+Configure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentrySDKLog+Configure.swift"; sourceTree = "<group>"; };
@@ -2615,7 +2615,7 @@
26152615
FABE8E162E307A7C0040809A /* Dependencies.swift */,
26162616
FA6FC0A92E0B6B0E00ED2669 /* SentrySdkInfo.swift */,
26172617
FA18417D2E4B457B005DEDC7 /* SentryApplication.swift */,
2618-
FA6614392E4B593000657755 /* SentryApplication+UIKit.swift */,
2618+
FA6614392E4B593000657755 /* SentryApplicationExtensions.swift */,
26192619
FA6615042E4BA4D200657755 /* ThreadSafeApplication.swift */,
26202620
FABE8E142E307A5C0040809A /* SentrySDK.swift */,
26212621
FA3A42712E1C5F9B00A08C39 /* SentryNSNotificationCenterWrapper.swift */,
@@ -5773,7 +5773,7 @@
57735773
FABE8E152E307A5E0040809A /* SentrySDK.swift in Sources */,
57745774
FA67DCFF2DDBD4EA00896B02 /* SentryMXManager.swift in Sources */,
57755775
D41415A72DEEE532003B14D5 /* SentryRedactViewHelper.swift in Sources */,
5776-
FA66143A2E4B593900657755 /* SentryApplication+UIKit.swift in Sources */,
5776+
FA66143A2E4B593900657755 /* SentryApplicationExtensions.swift in Sources */,
57775777
FA67DD002DDBD4EA00896B02 /* SentryMaskRenderer.swift in Sources */,
57785778
FA67DD012DDBD4EA00896B02 /* SentryMXCallStackTree.swift in Sources */,
57795779
FAAB29F12E3D252300ACD577 /* SentrySession.swift in Sources */,

Sources/Sentry/SentrySDKInternal.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ + (void)startWithOptions:(SentryOptions *)options
254254
// Reference to SentryCrashExceptionApplication to prevent compiler from stripping it
255255
[SentryCrashExceptionApplication class];
256256
#endif
257+
// These classes must be referenced somewhere for their files to not be stripped.
258+
[PlaceholderSentryApplication class];
259+
[PlaceholderProcessInfoClass class];
257260

258261
startInvocations++;
259262
startTimestamp = [SentryDependencyContainer.sharedInstance.dateProvider date];

Sources/Swift/Helper/SentryApplication.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,3 @@ import UIKit
3535
func relevantViewControllersNames() -> [String]?
3636
#endif // canImport(UIKit) && !SENTRY_NO_UIKIT
3737
}
38-
39-
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
40-
@objc @_spi(Private) extension NSApplication: SentryApplication {
41-
public var mainThread_isActive: Bool {
42-
isActive
43-
}
44-
}
45-
#endif

Sources/Swift/Helper/SentryApplication+UIKit.swift renamed to Sources/Swift/Helper/SentryApplicationExtensions.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// This is needed because a file that only contains an @objc extension will get automatically stripped out
2+
// in static builds. We need to either use the -all_load linker flag (which has downsides of app size increases)
3+
// or make sure that every file containing objc categories/extensions also have a concrete type that
4+
// is referenced. Once `SentryAppliction` is not using `@objc` this can be removed.
5+
@_spi(Private) @objc public final class PlaceholderSentryApplication: NSObject { }
6+
17
#if !os(macOS) && !os(watchOS) && !SENTRY_NO_UIKIT
28
import UIKit
39

@@ -150,3 +156,11 @@ extension SentryApplication {
150156
}
151157
}
152158
#endif
159+
160+
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
161+
@objc @_spi(Private) extension NSApplication: SentryApplication {
162+
public var mainThread_isActive: Bool {
163+
isActive
164+
}
165+
}
166+
#endif

Sources/Swift/Helper/SentryProcessInfo.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
var isMacCatalystApp: Bool { get }
1313
}
1414

15+
// This is needed because a file that only contains an @objc extension will get automatically stripped out
16+
// in static builds. We need to either use the -all_load linker flag (which has downsides of app size increases)
17+
// or make sure that every file containing objc categories/extensions also have a concrete type that
18+
// is referenced. Once `SentryProcessInfoSource` is not using `@objc` this can be removed.
19+
@_spi(Private) @objc public final class PlaceholderProcessInfoClass: NSObject { }
20+
1521
@_spi(Private) extension ProcessInfo: SentryProcessInfoSource {
1622
public var processDirectoryPath: String {
1723
Bundle.main.bundlePath

0 commit comments

Comments
 (0)