React Native实时数据库构建错误

React Native realtime database build error

所以我尝试将 firebase 数据库添加到现有项目中,它一直抛出这个 gradle 错误,但是当我创建一个新项目并安装它时,它工作正常,即使是我目前正在使用的项目工作是几个月前才完成的,所以它不是那么旧的项目,

这些是我的依赖项:

"@react-native-community/masked-view": "^0.1.11",
"@react-native-firebase/app": "^14.5.1",
"@react-native-firebase/database": "^14.5.1",
"@react-navigation/bottom-tabs": "^6.1.0",
"@react-navigation/native": "^6.0.7",
"@react-navigation/native-stack": "^6.3.0",
"@react-navigation/stack": "^6.1.0",
"firebase": "^9.6.9",
"intl": "^1.2.5",
"react": "17.0.2",
"react-moment": "^1.1.1",
"react-native": "0.67.3",

这些是我在控制台中获得的日志

> Configure project :react-native-firebase_database

Subproject ':react-native-firebase_database' has location '--\node_modules\@react-native-firebase\database\android' which is outside of the project root. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. Consult the upgrading guide for further information: https://docs.gradle.org/7.2/userguide/upgrading_version_7.html#deprecated_flat_project_structure



FAILURE: Build failed with an exception.

* What went wrong:

A problem occurred configuring project ':react-native-firebase_database'.

> Could not load compiled classes for build file '--\node_modules\@react-native-firebase\database\android\build.gradle' from cache.

* 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 1m 12s

at makeError (--\node_modules\@react-native-community\cli-platform-android\node_modules\execa\index.js:174:9)

at --\node_modules\@react-native-community\cli-platform-android\node_modules\execa\index.js:278:16

at processTicksAndRejections (node:internal/process/task_queues:96:5)

at async runOnAllDevices (--\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)

at async Command.handleAction (--\node_modules\@react-native-community\cli\build\index.js:192:9)

你好吗?

尝试将这些行包含在 android/settings.gradle.

include ':@react-native-firebase_app'
project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/app/android')

您也可以将compileSdkVersion设置为30或31。 targetSdkVersion 30 或以上。

干杯

所以基本上删除 gradle 缓存为我解决了这个问题,但是 gradlew clean 也不起作用所以我不得不删除缓存文件夹

  • 在 windows 上:%USERPROFILE%\.gradle\caches
  • 在 Mac/UNIX:~/.gradle/caches/

How to clear gradle cache?