13

我已将我的 ReactNative 项目从0.59 升级到 0.61.2 iOS 构建良好,但在 android 中我面临@react-native-community/cli-platform-android模块中的问题。

我的settings.gradle文件

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

我的build.gradle文件

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

构建应用程序时出现以下错误。

> Task :app:generatePackageList FAILED

FAILURE: Build failed with an exception.

* Where:
Script '/Users/yashwanth_c/Documents/projects/MobileApp/node_modules/@react-native-community/cli-platform-android
/native_modules.gradle' line: 130

* What went wrong:
Execution failed for task ':app:generatePackageList'.
> ReactNativeModules$_generatePackagesFile_closure3

* 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 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 5m 21s
4 actionable tasks: 4 executed

与往常一样,我清理了缓存并删除了 node_module 文件夹,尝试了很多次但没有运气。也用谷歌搜索了一个多星期,但仍然无法找到解决方法,不胜感激。

4

9 回答 9

9

我遇到了同样的问题,然后我尝试了以下命令。它对我有用。这意味着,手动安装 android cli 包。

npm i @react-native-community/cli-platform-android

如果有人知道另一种解决方案,请在这里分享。

于 2020-02-22T13:22:50.667 回答
9

我在 React Native 0.61.0 中遇到了同样的问题。我尝试了以下解决方案:-

  1. 关闭安卓工作室。
  2. 光盘安卓
  3. ./gradlew --stop (in MacOS)
  4. ./gradlew cleanBuildCache (in MacOS)

对于窗口:-

  1. gradlew --stop
  2. gradlew cleanBuildCache

检查以下链接以获取更多参考https://github.com/react-native-community/cli/issues/591

于 2020-04-11T05:40:28.393 回答
3

我在monorepo工作。该文件存在,但它在我的项目根目录中,而node_modules/@react-native-community不是包node_modules中。

为了解决这个问题,我更新了路径

/android/settings.gradle : Line 2

apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

/android/app/build.gradle : Line 225

apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
于 2020-06-20T17:53:28.407 回答
3

如果您的 react-native 应用无法在 android 模拟器上安装,

试着去

gradle-wrapper.propeties 

并更新

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

确保 gradle 已根据其适合的内容更新到稳定和最新的版本

于 2020-06-03T08:37:44.813 回答
2

我也面临同样的问题。我不知道,但由于某种原因,node_modules cli-platform-android包文件夹中没有显示。

然后我按照这些步骤来解决问题。

-> Remove `node_modules` folder
-> Remove `package-lock.json` file
-> Then install all the package again using `npm install`
-> Then `Rebuild the project in android studio`. That is how my issue was solved.
于 2021-03-28T10:10:12.510 回答
2

删除“node_modules”、“packagelock.json”文件夹,然后

yarn add @react-native-community/cli-platform-android@3.0.3
cd android && gradlew clean
于 2021-06-23T07:50:07.507 回答
1

就我而言,我使用的是 PNPM,所以我必须手动安装@react-native-community/cli-platform-android

于 2022-01-26T16:28:26.623 回答
0

您是否尝试使用 yarn 或 npm install 安装软件包?我遇到了同样的问题,然后我意识到我没有安装所有依赖项。

于 2021-12-18T04:50:55.173 回答
0

对于 Monorepo

就我而言,我正在使用单一代码库使用 3 个不同的应用程序开发 Monorepo。


//  packages/myapp/android/app/build.gradle:78

project.ext.react = [
    entryFile: "packages/myapp/index.js",
    enableHermes: false,  // clean and rebuild if changing
    cliPath: "../../node_modules/react-native/local-cli/cli.js",
]

// Update with extra '../' to point to the root `node_modules`
apply from: "../../../../node_modules/react-native/react.gradle"

于 2021-06-06T04:17:01.360 回答