React Native构建在android中失败,@ react-native-community / cli-platform-android /native_modules.gradle'行:130

时间:2019-12-20 09:13:18

标签: android reactjs react-native gradle

我已将我的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文件夹,尝试了很多次但没有运气。还用谷歌搜索了一个多星期,但仍然找不到解决方法,我们对此表示感谢。

8 个答案:

答案 0 :(得分:5)

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

  1. 关闭了Android Studio。
  2. cd android
  3. ./ gradlew --stop(在MacOS中)
  4. ./ gradlew cleanBuildCache(在MacOS中)

对于Window:-

  1. gradlew --stop
  2. 渐变cleanBuildCache

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

答案 1 :(得分:2)

如果您的本机应用程序无法在android模拟器上安装,

尝试去

gradle-wrapper.propeties 

并更新

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

请确保gradle已根据其需要更新为稳定最新的版本

答案 2 :(得分:1)

我也遇到了同样的问题。我不知道,但由于某种原因,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.

答案 3 :(得分:0)

我遇到了同样的问题,然后在命令下面尝试了。对我有用。 意思是,手动安装android cli软件包。

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

如果有人知道其他解决方案,请在这里分享。

答案 4 :(得分:0)

我在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)

答案 5 :(得分: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"

答案 6 :(得分:0)

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

yarn add @react-native-community/cli-platform-android@3.0.3
cd android && gradlew clean

答案 7 :(得分:-1)

通过0.60升级,RN进行了重大更改,例如自动链接程序包。 清洁gradle。

cd android
gradlew clean
cd ..
react-native run-android

如果不起作用,请尝试安装 jetifier