react-native project randomly started failing with
Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method exec() for arguments [ReactNativeModules$_getCommandOutput_closure16@45d8ac1c] on object of type org.gradle.api.internal.provider.DefaultProviderFactory_Decorated.
while running yarn android
It starts the JS server starts the emulator then fails
We have not changed anything in gradle and all versions are mentioned.
Original CLI error
A problem occurred evaluating script. Could not find method exec() for arguments [ReactNativeModules$_getCommandOutput_closure16@2763a6b8] on object of type org.gradle.api.internal.provider.DefaultProviderFactory_Decorated.
Path/package where error is occuring
node_modules/@react-native-community/cli-platform-android/native_modules.gradle
Exact code snippet where error is occuring
/**
* Runs a specified command using providers.exec in a specified directory.
* Throws when the command result is empty.
*/
String getCommandOutput(String[] command, File directory) {
try {
def execOutput = providers.exec { // the error is occuring here
commandLine(command)
workingDir(directory)
}
def output = execOutput.standardOutput.asText.get().trim()
if (!output) {
this.logger.error("${LOG_PREFIX}Unexpected empty result of running '${command}' command.")
def error = execOutput.standardError.asText.get().trim()
throw new Exception(error)
}
return output
} catch (Exception exception) {
this.logger.error("${LOG_PREFIX}Running '${command}' command failed.")
throw exception
}
}