@@ -59,3 +59,87 @@ dependencies {
5959 debugImplementation libs. flipper. network
6060 debugImplementation libs. flipper. soloader
6161}
62+
63+ // ===================================================================================================
64+ // AUTOLINKING AUTOMATION FOR NEW ARCHITECTURE
65+ // ===================================================================================================
66+ // This section automatically generates the autolinking.json file required for React Native's
67+ // New Architecture (Fabric + TurboModules). The file is only generated when newArchEnabled=true
68+ // and contains configuration data needed for CodeGen to generate native C++ bindings.
69+ // ===================================================================================================
70+ task generateAutolinking (type : Exec ) {
71+ description = ' Generates autolinking.json configuration file for React Native New Architecture'
72+ group = ' react-native'
73+
74+ workingDir project. rootDir. parent
75+ commandLine ' node' , ' generateAutolinking.js'
76+
77+ onlyIf {
78+ def newArchEnabled = findProperty(" newArchEnabled" )
79+ if (newArchEnabled != " true" && newArchEnabled != true ) {
80+ return false
81+ }
82+
83+ def autolinkingFile = file(" ${ project.rootDir} /build/generated/autolinking/autolinking.json" )
84+ def packageJsonFile = file(" ${ project.rootDir.parent} /package.json" )
85+ def configFile = file(" ${ project.rootDir.parent} /react-native.config.js" )
86+
87+ if (! autolinkingFile. exists()) {
88+ println " 📝 autolinking.json not found - will generate"
89+ return true
90+ }
91+
92+ def autolinkingTime = autolinkingFile. lastModified()
93+ def packageTime = packageJsonFile. exists() ? packageJsonFile. lastModified() : 0
94+ def configTime = configFile. exists() ? configFile. lastModified() : 0
95+
96+ if (packageTime > autolinkingTime || configTime > autolinkingTime) {
97+ println " 📝 Input files changed - will regenerate autolinking.json"
98+ return true
99+ }
100+
101+ println " ✅ autolinking.json is up to date - skipping generation"
102+ return false
103+ }
104+
105+ inputs. files(
106+ " ${ project.rootDir.parent} /package.json" ,
107+ " ${ project.rootDir.parent} /react-native.config.js"
108+ )
109+
110+ outputs. file(" ${ project.rootDir} /build/generated/autolinking/autolinking.json" )
111+
112+ doFirst {
113+ println " 🔄 Generating autolinking.json for React Native New Architecture..."
114+ }
115+
116+ doLast {
117+ println " ✅ autolinking.json generated successfully!"
118+ }
119+ }
120+
121+ /**
122+ * Automatic task dependency configuration
123+ * This ensures that autolinking.json is generated before any build tasks that require it.
124+ * The configuration runs after all build scripts are evaluated to ensure all tasks exist.
125+ */
126+ afterEvaluate {
127+ def newArchEnabled = findProperty(" newArchEnabled" )
128+
129+ if (newArchEnabled == " true" || newArchEnabled == true ) {
130+
131+ tasks. matching {
132+ it. name. startsWith(' generate' ) && it. name. contains(' NewArchitectureFiles' )
133+ }. configureEach {
134+ dependsOn generateAutolinking
135+ }
136+
137+ preBuild. dependsOn generateAutolinking
138+
139+ tasks. matching { it. name == ' generateAutolinkingPackageList' }. configureEach {
140+ dependsOn generateAutolinking
141+ }
142+
143+ println " 🔧 Autolinking automation configured for New Architecture"
144+ }
145+ }
0 commit comments