[React Native][0.71] 未找到 ID 为“com.facebook.react”的插件

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

未找到 ID 为“com.facebook.react”的插件。

1:任务因异常而失败。

  • 地点: 构建文件“android/app/build.gradle”行:2

  • 出了什么问题: 评估项目“:app”时出现问题。

未找到 ID 为“com.facebook.react”的插件。

==============================================================================

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

BUILD FAILED in 3s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'android/app/build.gradle' line: 2

* What went wrong:
A problem occurred evaluating project ':app'.
> Plugin with id 'com.facebook.react' not found.

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

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle

* 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
android react-native build.gradle
3个回答
8
投票

解决方案

classpath("com.facebook.react:react-native-gradle-plugin")
依赖项中添加
android/build.gradle

enter image description here


2
投票

我发现这个文档页面对于这个特定问题很有用,但它只是导致了一个新问题...我更普遍的问题的根源是我正在从较低版本的React Native升级,并且忘记了包括需要进行一些更改。解决此类问题的最佳方法是使用 React Native Upgrade Helper,它将使用示例应用程序准确地向您展示需要更改的内容。


0
投票

我遇到了同样的问题,构建失败并显示错误消息:

Plugin with id 'com.facebook.react' not found.
这是在尝试评估
build.gradle
中的项目“:app”时发生的。

对我有用的是删除

node_modules
目录,然后重新安装依赖项。以下是我遵循的步骤:

  1. 删除
    node_modules
    目录:
    rm -rf node_modules
    
    
  2. 清除 npm 缓存(可选但推荐):
    npm cache clean --force
    
  3. 重新安装依赖项:
    npm install
    

`

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