@@ -25,22 +25,79 @@ debug.log('Patching react-native-launch-arguments build.gradle', buildGradlePath
2525
2626if ( ! fs . existsSync ( buildGradlePath ) ) {
2727 debug . log ( 'build.gradle not found, skipping patch' ) ;
28- return ;
28+ } else {
29+ const buildGradle = fs . readFileSync ( buildGradlePath , 'utf8' ) ;
30+
31+ // Replace destinationDir with destinationDirectory.get() for Gradle 9+ compatibility
32+ const isPatched = buildGradle . includes ( 'destinationDirectory.get()' ) ;
33+ if ( ! isPatched ) {
34+ const patched = buildGradle . replace (
35+ / \. d e s t i n a t i o n D i r \b / g,
36+ '.destinationDirectory.get()'
37+ ) ;
38+
39+ fs . writeFileSync ( buildGradlePath , patched ) ;
40+ debug . log ( 'Patched react-native-launch-arguments build.gradle successfully!' ) ;
41+ } else {
42+ debug . log ( 'react-native-launch-arguments build.gradle is already patched!' ) ;
43+ }
2944}
3045
31- const buildGradle = fs . readFileSync ( buildGradlePath , 'utf8' ) ;
46+ // Patch iOS podspec for React Native 0.71+ compatibility
47+ // Replace 'React' with install_modules_dependencies() to fix RCTRegisterModule undefined symbol error in RN 0.84+ with dynamic frameworks
48+ const podspecPath = path . join (
49+ args [ 'app-dir' ] ,
50+ 'node_modules' ,
51+ 'react-native-launch-arguments' ,
52+ 'react-native-launch-arguments.podspec'
53+ ) ;
54+
55+ debug . log ( 'Patching react-native-launch-arguments podspec' , podspecPath ) ;
56+
57+ if ( fs . existsSync ( podspecPath ) ) {
58+ const podspec = fs . readFileSync ( podspecPath , 'utf8' ) ;
59+ debug . log ( 'Found podspec, checking for React dependency...' ) ;
60+
61+ // Check if already patched with install_modules_dependencies
62+ const isPatched = podspec . includes ( 'install_modules_dependencies' ) ;
63+ const hasReactDep = / s \. d e p e n d e n c y \s + [ ' " ] R e a c t [ ' " ] / . test ( podspec ) ;
64+ const hasReactCoreDep = / s \. d e p e n d e n c y \s + [ ' " ] R e a c t \/ C o r e [ ' " ] / . test ( podspec ) ;
65+ const hasReactCoreDepOnly = podspec . includes ( "s.dependency 'React-Core'" ) || podspec . includes ( 's.dependency "React-Core"' ) ;
66+
67+ debug . log ( `Podspec status: isPatched=${ isPatched } , hasReactDep=${ hasReactDep } , hasReactCoreDep=${ hasReactCoreDep } , hasReactCoreDepOnly=${ hasReactCoreDepOnly } ` ) ;
68+
69+ if ( ! isPatched && ( hasReactDep || hasReactCoreDep || hasReactCoreDepOnly ) ) {
70+ let patched = podspec ;
71+
72+ // Replace any React dependency with install_modules_dependencies(s)
73+ // This is the modern approach that works with all framework configurations (static, dynamic, etc.)
74+ // and automatically includes the correct React Native dependencies
75+ const installModulesDepsBlock = `
76+ if defined? install_modules_dependencies
77+ install_modules_dependencies(s)
78+ else
79+ s.dependency "React-Core"
80+ end` ;
3281
33- // Replace destinationDir with destinationDirectory.get() for Gradle 9+ compatibility
34- const isPatched = buildGradle . includes ( 'destinationDirectory.get()' ) ;
35- if ( ! isPatched ) {
36- const patched = buildGradle . replace (
37- / \. d e s t i n a t i o n D i r \b / g,
38- '.destinationDirectory.get()'
39- ) ;
82+ if ( hasReactDep ) {
83+ debug . log ( "Replacing s.dependency 'React' with install_modules_dependencies(s)" ) ;
84+ patched = patched . replace ( / \s + s \. d e p e n d e n c y \s + [ ' " ] R e a c t [ ' " ] \s * \n / g, installModulesDepsBlock + '\n' ) ;
85+ } else if ( hasReactCoreDep ) {
86+ debug . log ( "Replacing s.dependency 'React/Core' with install_modules_dependencies(s)" ) ;
87+ patched = patched . replace ( / \s + s \. d e p e n d e n c y \s + [ ' " ] R e a c t \/ C o r e [ ' " ] \s * \n / g, installModulesDepsBlock + '\n' ) ;
88+ } else if ( hasReactCoreDepOnly ) {
89+ debug . log ( "Replacing s.dependency 'React-Core' with install_modules_dependencies(s)" ) ;
90+ patched = patched . replace ( / \s + s \. d e p e n d e n c y \s + [ ' " ] R e a c t - C o r e [ ' " ] \s * \n / g, installModulesDepsBlock + '\n' ) ;
91+ }
4092
41- fs . writeFileSync ( buildGradlePath , patched ) ;
42- debug . log ( 'Patched react-native-launch-arguments build.gradle successfully!' ) ;
93+ fs . writeFileSync ( podspecPath , patched ) ;
94+ debug . log ( 'Patched react-native-launch-arguments podspec successfully!' ) ;
95+ } else if ( isPatched ) {
96+ debug . log ( 'react-native-launch-arguments podspec is already patched!' ) ;
97+ } else {
98+ debug . log ( 'Podspec does not contain React dependency - may already use install_modules_dependencies' ) ;
99+ }
43100} else {
44- debug . log ( 'react-native-launch-arguments build.gradle is already patched! ' ) ;
101+ debug . log ( 'podspec not found, skipping iOS patch ' ) ;
45102}
46103
0 commit comments