【发布时间】: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