找不到参数的 exec() 方法。 Android 构建错误

问题描述 投票:0回答:1

react-native 项目随机开始失败

原因:org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException:在 org.gradle.api.internal.provider.DefaultProviderFactory_Decolated 类型的对象上找不到参数 [ReactNativeModules$_getCommandOutput_closure16@45d8ac1c] 的方法 exec()。

跑步时

yarn android

启动 JS 服务器 启动模拟器然后失败

我们没有更改 gradle 中的任何内容,并且提到了所有版本。

原始 CLI 错误

评估脚本时出现问题。 在 org.gradle.api.internal.provider.DefaultProviderFactory_Decolated 类型的对象上找不到参数 [ReactNativeModules$_getCommandOutput_closure16@2763a6b8] 的方法 exec()。

发生错误的路径/包

node_modules/@react-native-community/cli-platform-android/native_modules.gradle

发生错误的确切代码片段


  /**
   * 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
    }
  }
android react-native gradle groovy android-gradle-plugin
1个回答
0
投票

我的项目遇到了这个问题,似乎最新的react-native 0.74版本在@react-native-community/cli-platform-android库上引入了问题。

因此,您必须更新您的 yarn.lockpackage-lock.json 文件并搜索行 react-native@*: 然后您必须删除所有依赖项并粘贴此代码:

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”

之后,删除节点模块文件夹并再次安装。

© www.soinside.com 2019 - 2024. All rights reserved.