Skip to content

Commit a99e920

Browse files
committed
android: inject ExecOperations for Gradle 9 compatibility
React Native 0.87 bumps the Gradle wrapper to 9.x, which removed Project.exec(). The linkNodeApiModules task used the bare `exec {}` closure in its doLast action, so every Android build (and the gradle.test.ts unit test on all platforms) failed with: Could not find method exec() ... on task ':react-native-node-api:linkNodeApiModules' Inject the ExecOperations service via an @Inject-annotated interface and call injectedExecOps.execOps.exec {} instead, the supported Gradle 9 replacement. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TVfanKvtyfSsoMgZv3DJtY
1 parent 601a706 commit a99e920

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

packages/host/android/build.gradle

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import java.nio.file.Paths
22
import groovy.json.JsonSlurper
3+
import javax.inject.Inject
34
import org.gradle.internal.os.OperatingSystem
5+
import org.gradle.process.ExecOperations
46

57
if (!System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR")) {
68
throw new GradleException([
@@ -161,17 +163,25 @@ dependencies {
161163
def commandLinePrefix = OperatingSystem.current().isWindows() ? ["cmd", "/c", "node"] : []
162164
def cliPath = file("../bin/react-native-node-api.mjs")
163165

166+
// Gradle 9 removed Project.exec(), so the ExecOperations service has to be
167+
// injected and used explicitly instead of the bare `exec {}` closure.
168+
interface InjectedExecOps {
169+
@Inject
170+
ExecOperations getExecOps()
171+
}
172+
def injectedExecOps = project.objects.newInstance(InjectedExecOps)
173+
164174
// Custom task to fetch jniLibs paths via CLI
165175
task linkNodeApiModules {
166176
doLast {
167-
exec {
177+
injectedExecOps.execOps.exec {
168178
commandLine commandLinePrefix + [cliPath, 'link', '--android', rootProject.rootDir.absolutePath]
169179
standardOutput = System.out
170180
errorOutput = System.err
171181
// Enable color output
172182
environment "FORCE_COLOR", "1"
173183
}
174-
184+
175185
android.sourceSets.main.jniLibs.srcDirs += file("../auto-linked/android").listFiles()
176186
}
177187
}

0 commit comments

Comments
 (0)