skip to Main Content

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


  1. 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:

    react-native@*:
      version “0.73.6”
      resolved “https://registry.yarnpkg.com/react-native/-/react-native-0.73.6.tgz#ed4c675e205a34bd62c4ce8b9bd1ca5c85126d5b”
      integrity "your integrity sha512"
      dependencies:
        “@jest/create-cache-key-function” “^29.6.3"
        “@react-native-community/cli” “12.3.6"
        “@react-native-community/cli-platform-android” “12.3.6"
        “@react-native-community/cli-platform-ios” “12.3.6"
        “@react-native/assets-registry” “0.73.1"
        “@react-native/codegen” “0.73.3"
        “@react-native/community-cli-plugin” “0.73.17"
        “@react-native/gradle-plugin” “0.73.4"
        “@react-native/js-polyfills” “0.73.1"
        “@react-native/normalize-colors” “0.73.2"
        “@react-native/virtualized-lists” “0.73.4"
        abort-controller “^3.0.0”
        anser “^1.4.9"
        ansi-regex “^5.0.0”
        base64-js “^1.5.1"
        chalk “^4.0.0”
        deprecated-react-native-prop-types “^5.0.0"
        event-target-shim “^5.0.1”
        flow-enums-runtime “^0.0.6"
        invariant “^2.2.4”
        jest-environment-node “^29.6.3"
        jsc-android “^250231.0.0”
        memoize-one “^5.0.0"
        metro-runtime “^0.80.3”
        metro-source-map “^0.80.3"
        mkdirp “^0.5.1”
        nullthrows “^1.1.1"
        pretty-format “^26.5.2”
        promise “^8.3.0"
        react-devtools-core “^4.27.7”
        react-refresh “^0.14.0"
        react-shallow-renderer “^16.15.0”
        regenerator-runtime “^0.13.2"
        scheduler “0.24.0-canary-efb381bbf-20230505”
        stacktrace-parser “^0.1.10"
        whatwg-fetch “^3.0.0”
        ws “^6.2.2"
        yargs “^17.6.2”
    

    After that, remove your node-modules folder and install all again.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search