@@ -7,14 +7,19 @@ const path = require('path');
77 * compatibility with use_frameworks! :linkage => :static (required by
88 * @react -native-firebase).
99 *
10- * Fixes three classes of errors:
10+ * Fixes four classes of errors:
1111 * 1. "include of non-modular header inside framework module" — sets
1212 * CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES for all pods.
1313 * 2. "declaration of 'X' must be imported from module 'Y' before it is required"
1414 * — adds use_modular_headers! so #import statements resolve correctly across
1515 * framework module boundaries.
1616 * 3. "RCTPromiseRejectBlock must be imported from module 'RNFBApp.RNFBAppModule'"
1717 * — patches RNFBMessaging source files to import RNFBAppModule explicitly.
18+ * 4. "unknown type name 'RCT_EXTERN'" / "duplicate declaration of method
19+ * 'RCT_CONCAT'" in RNFBMessagingModule.m (RCT_EXPORT_MODULE fails to expand)
20+ * — sets $RNFirebaseAsStaticFramework = true so the @react-native-firebase
21+ * pods build as static frameworks, letting React's macro headers resolve
22+ * inside the Firebase module.
1823 */
1924const withWebRTCFrameworkFix = ( config ) => {
2025 return withDangerousMod ( config , [
@@ -23,6 +28,28 @@ const withWebRTCFrameworkFix = (config) => {
2328 const podfilePath = path . join ( config . modRequest . platformProjectRoot , 'Podfile' ) ;
2429 let contents = fs . readFileSync ( podfilePath , 'utf-8' ) ;
2530
31+ // 0. Set $RNFirebaseAsStaticFramework = true at global scope (before any
32+ // target) so the @react-native-firebase pods build as static frameworks.
33+ // Without this, under use_frameworks! :linkage => :static the React
34+ // macro headers (RCT_EXTERN, RCT_CONCAT) don't resolve inside the
35+ // Firebase module and RCT_EXPORT_MODULE() fails to compile.
36+ if ( ! contents . includes ( '$RNFirebaseAsStaticFramework' ) ) {
37+ const fbAnchor = 'prepare_react_native_project!' ;
38+ const fbAnchorIdx = contents . indexOf ( fbAnchor ) ;
39+ if ( fbAnchorIdx === - 1 ) {
40+ throw new Error (
41+ '[withWebRTCFrameworkFix] Could not find prepare_react_native_project! in Podfile — ' +
42+ 'cannot place $RNFirebaseAsStaticFramework at global scope.'
43+ ) ;
44+ }
45+ const fbEndOfLine = contents . indexOf ( '\n' , fbAnchorIdx ) ;
46+ const fbInsertAt = fbEndOfLine === - 1 ? contents . length : fbEndOfLine + 1 ;
47+ contents =
48+ contents . slice ( 0 , fbInsertAt ) +
49+ '\n$RNFirebaseAsStaticFramework = true\n' +
50+ contents . slice ( fbInsertAt ) ;
51+ }
52+
2653 // 1. Add use_modular_headers! after use_frameworks! if not already present.
2754 if ( ! contents . includes ( 'use_modular_headers!' ) ) {
2855 const useFrameworksPattern = / u s e _ f r a m e w o r k s ! .* \n / g;
0 commit comments