简体   繁体   English

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

[英]React Native build failed in android, @react-native-community/cli-platform-android /native_modules.gradle' line: 130

I've upgraded my ReactNative project from 0.59 to 0.61.2 iOS is building fine but in android i'm facing the issue in @react-native-community/cli-platform-android module.我已将我的 ReactNative 项目从0.59 升级到 0.61.2 iOS 构建良好,但在 android 中我面临@react-native-community/cli-platform-android模块中的问题。

My settings.gradle file我的settings.gradle文件

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

My build.gradle file我的build.gradle文件

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

I get the following error while building the app.构建应用程序时出现以下错误。

> 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

As always i've cleaned the cache and deleted the node_module folder, tried many times but no luck.一如既往,我清理了缓存并删除了 node_module 文件夹,尝试了很多次但没有成功。 Also googled for more than a week but still not able to find a fix, any advice is appreciated.也用谷歌搜索了一个多星期,但仍然无法找到解决方法,不胜感激任何建议。

I was facing the same issue in React Native 0.61.0.我在 React Native 0.61.0 中遇到了同样的问题。 I have tried the below solution:-我尝试了以下解决方案:-

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

For Window:-对于窗户:-

  1. gradlew --stop
  2. gradlew cleanBuildCache

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

I had same issues then i tried below command.我遇到了同样的问题,然后我尝试了下面的命令。 it's worked for me.它对我有用。 It's mean, mannually install the android cli package.这意味着,手动安装 android cli 包。

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

If anyone known another solution kindly share here.如果有人知道另一种解决方案,请在此处分享。

If your react-native app fails to install on android emulator,如果您的 react-native 应用程序无法在 android 模拟器上安装,

try going to尝试去

gradle-wrapper.propeties 

and update并更新

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

Make sure that gradle is updated to the stable and lastest version according to what it suits确保 gradle 根据它适合的内容更新到稳定和最新版本

I'm working in a monorepo.我在 monorepo 工作。 The file exists, but it was in my project root's node_modules/@react-native-community NOT the package node_modules .该文件存在,但它在我的项目根目录的node_modules/@react-native-community不是包node_modules

To fix this, I updated the paths为了解决这个问题,我更新了路径

/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)

I have also face the same kind of problem.我也面临同样的问题。 I don't know but for some reason, in the node_modules cli-platform-android package folder was not showing.我不知道,但由于某种原因,在node_modules cli-platform-android包文件夹中没有显示。

Then I follow these steps, to solve the issue.然后我按照这些步骤来解决这个问题。

-> 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.

In my case I was using PNPM, so I had to manually install @react-native-community/cli-platform-android在我的例子中,我使用的是 PNPM,所以我必须手动安装@react-native-community/cli-platform-android

For Monorepo对于 Monorepo

In my case I am working on Monorepo with 3 different apps using single code base.就我而言,我正在使用单一代码库使用 3 个不同的应用程序处理 Monorepo。


One

//  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"

Delete "node_modules", "packagelock.json" folders and then删除“node_modules”、“packagelock.json”文件夹,然后

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

Did you try installing packages using yarn or npm install?您是否尝试使用 yarn 或 npm install 安装软件包? i was facing the same issue then I realized I did not install all the dependencies.我遇到了同样的问题,然后我意识到我没有安装所有的依赖项。

Just go to your MainActivity.java file located on C:\...path...\..\android\app\src\main\java\com\appname\MainActivity.java只需 go 到位于 C 的MainActivity.java文件C:\...path...\..\android\app\src\main\java\com\appname\MainActivity.java

just remove any imports above package com.yourappname;只需删除package com.yourappname; and put them below it as below并将它们放在下面,如下所示

package com.driverapp; //nothing above of this line that says package com.xxx

import android.os.Bundle;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {
...

In my case, it is because the package name has move from AndroidManifest.xml to build.gradle .就我而言,这是因为 package 名称已从AndroidManifest.xml移动到build.gradle Solved it by adding the package name back to AndroidManifest.xml通过将 package 名称添加回AndroidManifest.xml解决了这个问题

I had the same problem because I switched branches.我有同样的问题,因为我换了分支。 You can try removing these things and reinstalling the dependencies to solve the problem.你可以尝试把这些东西去掉,重新安装依赖来解决问题。

delelte these:删除这些:

android\build机器人\构建

android\app\build安卓\应用程序\构建

node_modules节点模块

yarn.lock纱线锁

package.lock.json package.lock.json

re-execute yarn重新执行纱线

yarn install
yarn android

With the 0.60 upgrade RN made major changes like auto linking packages.随着 0.60 升级,RN 进行了重大更改,例如自动链接包。 Clean the gradle.清洁gradle。

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

if it doesn't work try to install jetifier .如果它不起作用尝试安装jetifier

暂无
暂无

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

相关问题 找不到模块 node_modules\@react-native-community\cli\build\bin.js' - Cannot find module node_modules\@react-native-community\cli\build\bin.js' 尝试运行 android 项目时找不到模块“@react-native-community/cli” - Cannot find module '@react-native-community/cli' when trying to run the android project 如何通过@react-native-community/slider 在 android 中创建垂直滑块? - how to create vertical slider in android by @react-native-community/slider? react-native-community / react-native-netinfo 监听器不在 android 上工作 - react-native-community / react-native-netinfo listners are not working on android 使用 @react-native-community/blur 和 react-native 0.66.3 在 android 上崩溃 - using @react-native-community/blur with react-native 0.66.3 crash on android 反应原生 android APK 发布构建失败 gradle - React native android APK release build failed gradle 反应原生 gradle 构建失败 - React native gradle build failed react-native run-android 给出错误 FAILURE:Build failed Where: Build file 'C:\...\node_modules\react-native-gradle-plugin\build.gradle.kts' 行:11 - react-native run-android gives err FAILURE:Build failed Where: Build file 'C:\...\node_modules\react-native-gradle-plugin\build.gradle.kts' line: 11 android构建中的gradle错误反应原生 - gradle error in android build react native 模糊在 Android @react-native-community/blur 上无法正常工作 - Blur doesn't work correctly on Android @react-native-community/blur
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM