From a99e920415246d22ce36f4afb633506b43d62830 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 24 Jul 2026 18:08:27 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01TVfanKvtyfSsoMgZv3DJtY --- packages/host/android/build.gradle | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/host/android/build.gradle b/packages/host/android/build.gradle index 39204133..396fd8f2 100644 --- a/packages/host/android/build.gradle +++ b/packages/host/android/build.gradle @@ -1,6 +1,8 @@ import java.nio.file.Paths import groovy.json.JsonSlurper +import javax.inject.Inject import org.gradle.internal.os.OperatingSystem +import org.gradle.process.ExecOperations if (!System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR")) { throw new GradleException([ @@ -161,17 +163,25 @@ dependencies { def commandLinePrefix = OperatingSystem.current().isWindows() ? ["cmd", "/c", "node"] : [] def cliPath = file("../bin/react-native-node-api.mjs") +// Gradle 9 removed Project.exec(), so the ExecOperations service has to be +// injected and used explicitly instead of the bare `exec {}` closure. +interface InjectedExecOps { + @Inject + ExecOperations getExecOps() +} +def injectedExecOps = project.objects.newInstance(InjectedExecOps) + // Custom task to fetch jniLibs paths via CLI task linkNodeApiModules { doLast { - exec { + injectedExecOps.execOps.exec { commandLine commandLinePrefix + [cliPath, 'link', '--android', rootProject.rootDir.absolutePath] standardOutput = System.out errorOutput = System.err // Enable color output environment "FORCE_COLOR", "1" } - + android.sourceSets.main.jniLibs.srcDirs += file("../auto-linked/android").listFiles() } }