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

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

我正在生成一个使用 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>

如何解决这个问题?

javascript android react-native gradle execution
8个回答
24
投票

我刚刚遇到了同样的问题,并且能够找出它在我的系统上发生的原因。使用

--stacktrace
标志有助于弄清楚发生了什么,最终指向
react-native-community/cli
包。

扫描

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

我的系统上有 Gradle 7,并降级到 Gradle 6,运行

gradle wrapper
,然后
./gradlew clean
让我可以继续前进。

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


15
投票

使用 Gradle 版本 6.9

以下是此版本的亮点:

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

使用 Gradle Wrapper 更改版本。

./gradlew wrapper --gradle-version 6.9

10
投票

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

reactNativeModule
参数。

看起来

ArrayList<HashMap<String, String>>[] packages = this.reactNativeModules
,确实不匹配。

确实

reactNativeModule
在他的声明中没有括号。

所以我将

native_modules.gradle
中的以下行更改为:

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

至:

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

2
投票

使用

npx react-native upgrade

将您的 React-Native 版本升级到最新版本

我必须从 JDK 1.8 升级到 11,并且发生了此错误。

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


2
投票

解决该问题的步骤React Native*

  1. 在您的

    apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
    中找到
    app -> build.gradle

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

  3. 注释掉其中一个。

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


1
投票

在 gradle/wrapper/gradle-wrapper.properties 中用

https\://services.gradle.org/distributions/gradle-6.9-all.zip
替换 distributionUrl 为我解决了所有问题。感谢上帝


1
投票

对于我来说

react-native
版本
0.70.6

问题是由于

@react-native-community/cli-platform-android
版本造成的,所以我只需要运行

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

如给这里


-1
投票

按照此处所述升级

@react-native-community/cli
解决了我的问题:https://github.com/react-native-community/cli#updating-the-cli

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

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