Description
When using use_frameworks! :linkage => :static in the Podfile (which is common for projects using Firebase, React Native New Architecture, or any pod with Swift code), the iOS build fails with:
'OpentokReactNative-Swift.h' file not found
The error occurs in 3 files:
ios/OpentokReactNative.mm (line 3)
ios/OTRNSubscriberComponentView.mm (line 10)
ios/OTRNPublisherComponentView.mm (line 10)
Environment
opentok-react-native: 2.31.1
- React Native: 0.81.5
- Expo SDK: 54
- New Architecture: Enabled (Fabric + TurboModules)
- Xcode: 16.x
- iOS target: 18.5
- Podfile:
use_frameworks! :linkage => :static
Root Cause
In all 3 .mm files, the Swift bridging header is imported as:
#import <OpentokReactNative-Swift.h>
When CocoaPods builds pods as static frameworks (use_frameworks! :linkage => :static), the auto-generated Swift bridging header is placed inside the framework's Headers/ directory. The correct import path then becomes <OpentokReactNative/OpentokReactNative-Swift.h>.
The current import only works when pods are built as static libraries (without use_frameworks!).
Affected Files
ios/OpentokReactNative.mm — TurboModule native implementation
ios/OTRNSubscriberComponentView.mm — Fabric subscriber component
ios/OTRNPublisherComponentView.mm — Fabric publisher component
Suggested Fix
Use __has_include in all 3 files to support both configurations:
#if __has_include(<OpentokReactNative/OpentokReactNative-Swift.h>)
#import <OpentokReactNative/OpentokReactNative-Swift.h>
#else
#import <OpentokReactNative-Swift.h>
#endif
This is a common pattern used by other React Native libraries (e.g., react-native-vision-camera, react-native-screens) to ensure compatibility with both use_frameworks! and non-framework setups.
Workaround
We are currently using a patch-package patch to apply the fix locally on all 3 files:
diff --git a/ios/OpentokReactNative.mm b/ios/OpentokReactNative.mm
@@ -1,6 +1,10 @@
#import <Foundation/Foundation.h>
#import <OpentokReactNative/RNOpentokReactNativeSpec.h>
-#import <OpentokReactNative-Swift.h>
+#if __has_include(<OpentokReactNative/OpentokReactNative-Swift.h>)
+#import <OpentokReactNative/OpentokReactNative-Swift.h>
+#else
+#import <OpentokReactNative-Swift.h>
+#endif
diff --git a/ios/OTRNSubscriberComponentView.mm b/ios/OTRNSubscriberComponentView.mm
@@ -7,7 +7,11 @@
#import <OpentokReactNative/RNOpentokReactNativeSpec.h>
#import <React/RCTConversions.h>
#import <React/RCTViewComponentView.h>
-#import <OpentokReactNative-Swift.h>
+#if __has_include(<OpentokReactNative/OpentokReactNative-Swift.h>)
+#import <OpentokReactNative/OpentokReactNative-Swift.h>
+#else
+#import <OpentokReactNative-Swift.h>
+#endif
diff --git a/ios/OTRNPublisherComponentView.mm b/ios/OTRNPublisherComponentView.mm
@@ -7,7 +7,11 @@
#import <OpentokReactNative/RNOpentokReactNativeSpec.h>
#import <React/RCTConversions.h>
#import <React/RCTViewComponentView.h>
-#import <OpentokReactNative-Swift.h>
+#if __has_include(<OpentokReactNative/OpentokReactNative-Swift.h>)
+#import <OpentokReactNative/OpentokReactNative-Swift.h>
+#else
+#import <OpentokReactNative-Swift.h>
+#endif
Steps to Reproduce
- Create a React Native project with
use_frameworks! :linkage => :static in the Podfile
- Install
opentok-react-native@2.31.1
- Enable the New Architecture (
RCT_NEW_ARCH_ENABLED=1)
- Run
pod install
- Build for iOS
Expected: Build succeeds
Actual: Build fails with 'OpentokReactNative-Swift.h' file not found in all 3 .mm files (fails on the first one encountered)
Description
When using
use_frameworks! :linkage => :staticin the Podfile (which is common for projects using Firebase, React Native New Architecture, or any pod with Swift code), the iOS build fails with:The error occurs in 3 files:
ios/OpentokReactNative.mm(line 3)ios/OTRNSubscriberComponentView.mm(line 10)ios/OTRNPublisherComponentView.mm(line 10)Environment
opentok-react-native: 2.31.1use_frameworks! :linkage => :staticRoot Cause
In all 3
.mmfiles, the Swift bridging header is imported as:When CocoaPods builds pods as static frameworks (
use_frameworks! :linkage => :static), the auto-generated Swift bridging header is placed inside the framework'sHeaders/directory. The correct import path then becomes<OpentokReactNative/OpentokReactNative-Swift.h>.The current import only works when pods are built as static libraries (without
use_frameworks!).Affected Files
ios/OpentokReactNative.mm— TurboModule native implementationios/OTRNSubscriberComponentView.mm— Fabric subscriber componentios/OTRNPublisherComponentView.mm— Fabric publisher componentSuggested Fix
Use
__has_includein all 3 files to support both configurations:This is a common pattern used by other React Native libraries (e.g.,
react-native-vision-camera,react-native-screens) to ensure compatibility with bothuse_frameworks!and non-framework setups.Workaround
We are currently using a
patch-packagepatch to apply the fix locally on all 3 files:Steps to Reproduce
use_frameworks! :linkage => :staticin the Podfileopentok-react-native@2.31.1RCT_NEW_ARCH_ENABLED=1)pod installExpected: Build succeeds
Actual: Build fails with
'OpentokReactNative-Swift.h' file not foundin all 3.mmfiles (fails on the first one encountered)