繁体   English   中英

(React Native):任务 ':app:generatePackageList' 执行失败

[英](React Native): Execution failed for task ':app:generatePackageList'

我正在生成一个我使用 React Native 开发的项目的 apk。 但是当我运行命令./gradlew assembleRelease时出现如下错误:

> Configure project :react-native-audio
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see http://d.android.com/r/tools/update-dependency-configurations.html.

> Task :app:generatePackageList FAILED

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\romer\ProjetoAP\Gravador\teste\Gravador_de_audio\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 131

* What went wrong:
Execution failed for task ':app:generatePackageList'.
> argument type mismatch

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 24s
1 actionable task: 1 executed
PS C:\users\romer\ProjetoAP\Gravador\teste\Gravador_de_audio\android>

如何解决这个问题呢?

我刚刚遇到了同样的问题,并且能够追查为什么它会在我的系统上发生。 使用--stacktrace标志有助于弄清楚发生了什么,最终指向react-native-community/cli package。

在扫描react-native-community/cli repo 中的问题和 PR 后,我发现了这个 PR https://github.com/react-native-community/cli/pull/1396 ,它增加了对 Gradle 7 的支持。

我的系统上有 Gradle 7 并降级到 Gradle 6,运行gradle wrapper ,然后./gradlew clean让我继续前进。

希望能解决您的问题,或者至少让您了解如何在系统上追踪它!

我没有降级,而是检查了第 131 行提到的reactNativeModule参数。

看起来像ArrayList<HashMap<String, String>>[] packages = this.reactNativeModules ,实际上是不匹配的。

事实上, reactNativeModule在他的声明中没有括号。

所以我改变了:

ArrayList<HashMap<String, String>>[] packages = this.reactNativeModules

ArrayList<HashMap<String, String>> packages = this.reactNativeModules

使用 Gradle 版本 6.9

以下是此版本的亮点:

  • 这是一个小的向后移植版本
  • Java 16与 Java 工具链一起使用时可用于编译
  • 动态版本可以在插件声明中使用
  • Apple Silicon 处理器的原生支持

使用 Gradle Wrapper 更改版本。

./gradlew wrapper --gradle-version 6.9

+1 降级到 6。我今天想做一些升级,但结果相反。

npx react-native upgrade您的 react-native 版本升级到最新版本

我不得不从 JDK 1.8 升级到 11 并且发生了这个错误。

感谢 J Myers 的回答,我发现我必须升级 react native 版本: https://github.com/react-native-community/cli/pull/1396

用 gradle/wrapper/gradle-wrapper.properties 中的https\://services.gradle.org/distributions/gradle-6.9-all.zip替换 distributionUrl 为我修复了一切。 感谢上帝

React Native解决问题的步骤 *

  1. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 在您的应用程序中应用apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) app -> build.gradle

  2. 检查这行代码是否重复。

  3. 注释掉其中之一。

这应该可以解决您的问题。

对我来说react-native版本0.70.6

问题是由于@react-native-community/cli-platform-android版本所以我只需要运行

yarn add @react-native-community/cli-platform-android

作为这里

按照此处所述升级@react-native-community/cli为我解决了这个问题: https://github.com/react-native-community/cli#updating-the-cli

如果你使用锁定文件(yarn.lock 或 package-lock.json)——找到所有带@react-native-community/cli 前缀的条目,删除它们,再次运行 yarn install / npm install。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM