【问题标题】:FirebaseAuth class now missing "getCurrentUser()" method?FirebaseAuth 类现在缺少“getCurrentUser()”方法?
【发布时间】:2023-04-08 16:01:02
【问题描述】:

Firebase 昨天工作得很好,但我今天早上打开我的项目只是发现 FirebaseAuth 类现在没有任何对 FirebaseUser 类的引用。我找不到getCurrentUser() 方法。

不过是班上的Google doc still shows that it exists

我在那个班级的imports

import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GetTokenResult;
import com.google.firebase.auth.GoogleAuthProvider;

build.gradle:

api 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.firebase:firebase-admin:6.3.0'

是的:

  • 我的build.gradle 中有apply plugin: 'com.google.gms.google-services'
  • 我的应用程序的build.gradle 中包含repositories { google() jcenter() }
  • 我有Clean 我的项目没有出错
  • 我已经重启AndroidStudio

我的应用程序中的当前错误(似乎从昨天开始就突然出现):

  • getCurrentUser() 方法在我的FirebaseAuth 类(已导入)中不再存在。其 signInWithCredential(...)signOut()createUserWithEmailAndPassword(...)signInWithEmailAndPassword(...) 方法也是如此。
  • isEmailVerified() 方法在我的FirebaseUser 类中不再存在
  • 尝试Make Project 时,我收到此错误:Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration. - auto-value-1.4.jar (com.google.auto.value:auto-value:1.4) Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
  • build.gradleimplementation 'com.android.support:appcompat-v7:27.1.1' 现在突出显示为错误 (All com.android.support librairies must have the same version specification)

我的完整build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.payne.simpletestapp"
        minSdkVersion 16
        targetSdkVersion 27
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    api 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.firebase:firebase-admin:6.3.0'

    implementation 'org.osmdroid:osmdroid-android:6.0.1'
    implementation 'org.osmdroid:osmdroid-wms:6.0.1'
    implementation 'org.osmdroid:osmdroid-mapsforge:6.0.1'
    implementation 'org.osmdroid:osmdroid-geopackage:6.0.1'
    api 'com.github.MKergall:osmbonuspack:6.5.1'


    implementation 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
    api 'org.apache.httpcomponents:httpclient-android:4.3.5'

    implementation 'com.squareup.picasso:picasso:2.71828'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.6'


}

repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}

apply plugin: 'com.google.gms.google-services'

请帮忙?我花了几天时间来构建这个类,但现在它不起作用。

【问题讨论】:

  • 请注意,firebase-admin 旨在用于服务器,而不是 Android 应用程序。见stackoverflow.com/a/42103063/4815718
  • build.gradle 中删除firebase-admin 并按Sync now 解决了问题!奇怪:我什至把它放回那里只是为了测试它,项目很好。 (从那以后我再次​​删除它。我一直想知道这是否只在服务器端需要。)当你在这里时,你介意我问一下:我应该把我的firebase-adminsdk.json 和@987654359 @ 在我服务器的 Java 项目中?我的服务器需要哪个keys/secrets 来解密/验证idToken JWT 的第三部分?谢谢!!
  • 我没有经验来帮助解决其他问题。最好提出一个新问题。
  • already have,您实际上回答了我列出的其中一个问题,因此我在这里抓住机会。无论如何谢谢。 :)

标签: java android firebase google-api firebase-authentication


【解决方案1】:

build.gradle 中删除firebase-admin 并按Sync now 解决了这个问题!

感谢 BobSnyder(在 cmets 中)。

【讨论】:

    【解决方案2】:

    该方法仍然存在。 Android Studio 可能会感到困惑,可能是因为您的项目 .idea 文件夹中的某些内容已损坏。

    尝试退出 Android Studio,删除项目根目录下的 .idea 文件夹,然后再次将项目导入 Android Studio。

    【讨论】:

      【解决方案3】:

      转到File -> Invalidate caches and restart 菜单。

      【讨论】:

        【解决方案4】:

        该方法存在,稍作修改。

        尝试使用它 FirebaseUser 用户 = FirebaseAuth.getInstance().getCurrentUser();

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-12-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-09
          • 2017-06-28
          • 2020-06-11
          相关资源
          最近更新 更多