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
}
}
2
Answers
I had this issue on my project, it seems that the latest react-native 0.74 version introduced issues on the @react-native-community/cli-platform-android library.
So you have to update your yarn.lock or package-lock.json file and search for the line react-native@*: then you have to remove all of dependencies and paste this code instead:
After that, remove your node-modules folder and install all again.
Got same exception after upgrde to new version (0.74) of RN.
In my case the problem was an old
androidgradlew.bat
It was created with previos RN version.
I copied gradlew.bat from blank project, and this issue moved away.
You may create reference project from last RN
npx @react-native-community/cli@latest init TestProject
P.S.
There are a lot other diffirences in *.gradle files comes with new version of RN.