【问题标题】:Can't run the project after installing react-native-video安装 react-native-video 后无法运行项目
【发布时间】:2022-06-17 03:05:21
【问题描述】:

将 react-native-video 添加到新创建的项目后,当我想运行项目(android)时出现此错误,但一旦我卸载它,一切运行正常。

info JS server already running.
info Installing the app...

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\myTestApp\myTestApp\android\build.gradle' line: 19

* What went wrong:
A problem occurred evaluating root project 'myTestApp'.      
> Could not find method compile() for arguments [project ':react-native-video'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* 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

BUILD FAILED in 9s

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.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\myTestApp\myTestApp\android\build.gradle' line: 19

* What went wrong:
A problem occurred evaluating root project 'myTestApp'.      
> Could not find method compile() for arguments [project ':react-native-video'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* 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

BUILD FAILED in 9s

    at makeError (C:\myTestApp\myTestApp\node_modules\execa\index.js:174:9)
    at C:\myTestApp\myTestApp\node_modules\execa\index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async runOnAllDevices (C:\myTestApp\myTestApp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
    at async Command.handleAction (C:\myTestApp\myTestApp\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
npm ERR! code ELIFECYCLE

我根据文档将 react-native-video 添加到我的项目中。

   npm install --save react-native-video
   cd myTestApp
   npm run android

然后当我运行项目时出现上述错误

【问题讨论】:

  • 看起来您在 android/build.gradle 中添加了 compile('react-native-video') 而不是 android /app/build.gradle 文件。
  • 谢谢,Akshay,但在将 compile('react-native-video') 添加到 android/app/build.gradle 后,我仍然遇到同样的问题

标签: react-native react-native-video


【解决方案1】:

找到了解决方案here

转到文件:node_module/react-native-video/android-exoplayer/build.gradle

将 2.13.2 的所有引用更改为 2.13.3

【讨论】:

  • 只是想知道,node_modules 不是不应该编辑的东西吗?由于新的 npm 命令将删除您所做的更改?除非你在代码中克隆 npm 模块?
【解决方案2】:

enter image description here

我有同样的问题,修改 build.gradle 不为我服务,我反应原生 0.68.2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 2021-06-12
    • 1970-01-01
    • 2021-12-20
    相关资源
    最近更新 更多