Skip to content

[iOS] Build fails with 'OpentokReactNative-Swift.h' file not found when using use_frameworks! :linkage => :static #936

@alexbrtin

Description

@alexbrtin

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

  1. ios/OpentokReactNative.mm — TurboModule native implementation
  2. ios/OTRNSubscriberComponentView.mm — Fabric subscriber component
  3. 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

  1. Create a React Native project with use_frameworks! :linkage => :static in the Podfile
  2. Install opentok-react-native@2.31.1
  3. Enable the New Architecture (RCT_NEW_ARCH_ENABLED=1)
  4. Run pod install
  5. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions