简体   繁体   English

无法解析 FirebaseFirestore Android

[英]Cannot resolve FirebaseFirestore Android

I followed the official firebase android guide, but whenever I try to instantiate the FirebaseFirestore, I get a "cannot resolve symbol" error.我遵循了官方的 firebase android 指南,但是每当我尝试实例化 FirebaseFirestore 时,都会出现“无法解析符号”错误。 The issue is as shown below:问题如下图所示: 在此处输入图片说明

Before this is marked as a duplicate, I have been searching for a solution to this issue for hours now.在将其标记为重复之前,我几个小时以来一直在寻找解决此问题的方法。 Nothing I found online works.我在网上找到的任何作品都没有。 Below is my gradle config: app:下面是我的 gradle 配置:应用程序:

在此处输入图片说明

root:根: 在此处输入图片说明

Is there any idea what I am doing wrong?知道我做错了什么吗? I have tried various different plugin versions for fireStore and firebase app but nothing seems to work我为 fireStore 和 firebase 应用程序尝试了各种不同的插件版本,但似乎没有任何效果

it all hints for, that the artifact had not yet been downloaded...这一切都暗示着,该工件尚未下载......

check if Gradle isn't in offline mode;检查 Gradle 是否未处于离线模式; and sync or build the project once.并同步或构建项目一次。

alternatively, run ./gradlew clean assembleDebug from a terminal.或者,从终端运行./gradlew clean assembleDebug

repository mavenCentral() is also rather relevant than mavenLocal() .存储库mavenCentral()也比mavenLocal()相关。

while the repository for these artifacts should be the google() one.而这些工件的存储库应该是google()一个。

another known issue is, that one may have to prefer IPv4, in the gradle.properties file:另一个已知问题是,在gradle.properties文件中,人们可能不得不更喜欢 IPv4:

org.gradle.jvmargs=-Djava.net.preferIPv4Stack=true

尝试关闭您的项目并重新导入

Looks like you have missed import statement看起来你错过了导入语句

import com.google.firebase.firestore.FirebaseFirestore;

在此处输入图片说明

Try this:-尝试这个:-

  1. In Android Studio, click on File.在 Android Studio 中,单击文件。
  2. Then click Sync Project with Gradle Files.然后单击将项目与 Gradle 文件同步。

I Recently Had that Error and this are the steps that I tried, I am not pretty sure which one of these did the trick but the error was solved and I was able to utilize fireStore.我最近遇到了那个错误,这是我尝试过的步骤,我不太确定其中哪一个可以解决问题,但错误已解决,我能够使用 fireStore。 These are not in any Order I just randomly continued doing these.这些没有任何顺序我只是随机地继续做这些。

I hope these helps.我希望这些有帮助。 Check for these检查这些

1. Have You Installed Google Play Services and Google Repository. 1. 您是否安装了 Google Play Services 和 Google Repository。

Check for the Updated Version and install it if available.检查更新版本并安装它(如果可用)。

2. Try to Match All the Versions in the gradle config: app ... for eg, 2. 尝试匹配gradle 配置中的所有版本: app ... 例如,

     implementation 'com.google.firebase:firebase-core:16.0.3'
     implementation 'com.google.firebase:firebase-firestore:16.0.3'

Sync Those Files for Quite few times多次同步这些文件

3. Clear Caches and Restart the Android Studio IDE 3.清除缓存并重启Android Studio IDE

Step 1:- Go to File Menu > Invalidate Caches/Restart..第 1 步:- 转到文件菜单 > 使缓存无效/重新启动..
Step 2:- Click on Invalidate and Restart on the Window that Appears第 2 步:- 在出现的窗口上单击无效并重新启动

This will restart the project and rebuild it, Stay calm as this can take quite a time.这将重新启动项目并重建它,保持冷静,因为这可能需要相当长的时间。


After Following These Steps all my Error were Solved and I was able to instantiate the FirebaseFirestore.遵循这些步骤后,我的所有错误都解决了,我能够实例化 FirebaseFirestore。

project build.gradle项目 build.gradle

allprojects {
   repositories {
      google()
      jcenter()
      maven { url 'https://jitpack.io' }
}}

Try adding this to your gradle尝试将其添加到您的 gradle 中

The FirestoreRecyclerAdapter class is part of the FirebaseUI Library but not the core Firestore SDK FirestoreRecyclerAdapter 类是 FirebaseUI 库的一部分,但不是核心 Firestore SDK

implementation 'com.firebaseui:firebase-ui-firestore:4.3.1'

I recently faced this problem.我最近遇到了这个问题。 there is a simple solution.有一个简单的解决方案。

  1. add this to your app gradle implementation 'com.google.android.gms:play-services-base:15.0.1' implementation 'com.firebaseui:firebase-ui-firestore:4.3.1'将此添加到您的应用程序 gradle implementation 'com.google.android.gms:play-services-base:15.0.1' implementation 'com.firebaseui:firebase-ui-firestore:4.3.1'

  2. Import the following statement import com.google.firebase.firestore.FirebaseFirestore;导入以下语句 import com.google.firebase.firestore.FirebaseFirestore;

Thank me later :)晚点再谢我 :)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM