Firebase身份验证突然停止工作

时间:2020-05-29 15:28:23

标签: java android firebase firebase-authentication

我有一个不需要登录的android应用程序,但是我确实启用了匿名登录,以便可以从Firebase检索userID并将其用于记录特定事件。我感觉它只是停止从Firebase检索UID。

我为解决此问题所做的工作如下:

  • 更新了所有依赖项
  • 更新了模拟器
  • 安装了新的模拟器
  • 重新添加了Google服务插件
  • 重新添加了google-services.json文件
  • 更新了Android清单
  • 为了进行测试,我试图创建一个登录活动,该活动通过带有onclicklisterer的按钮来使用户匿名登录。
  • 我已经仔细检查了Android Studio中的“本地历史记录”,以查看是否对代码进行了大的更改,实际情况并非如此。 See screenshot
  • 从Firebase控制台启用和禁用匿名登录。
  • 基于Firebase的documentation重新编写了整个代码。
  • 我基本上已经尝试了每种解决方案

我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.superawesome.metime">


    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/wazzup"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".Cardview" />
        <activity android:name=".cardviewactivity" />


        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxx" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.google.firebase.auth.internal.FederatedSignInActivity"
            tools:replace="android:launchMode"
            android:launchMode="standard" />

        <service
            android:name=".MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>
    </application>

</manifest>

我的代码:

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true; // go back to the first screen

        case R.id.cardoverview:
            startActivity(new Intent(this, cardviewactivity.class));
            return true; //go to the screen where all the swiped right activities are stored


    }
    return super.onOptionsItemSelected(item);
}

@Override
protected void onStart() {
    super.onStart();
    mAuth.addAuthStateListener(mAuthListener);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    FirebaseInstanceId.getInstance().getInstanceId()
            .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                @Override
                public void onComplete(@NonNull Task<InstanceIdResult> task) {
                    if (!task.isSuccessful()) {
                        Log.w("This Tag", "getInstanceId failed", task.getException());
                        return;
                    } else {
                        Log.d("This tag", "We need this");
                    }
                }
            });

    swipeDb = FirebaseDatabase.getInstance().getReference().child("Users");
    final FirebaseFirestore db = FirebaseFirestore.getInstance();


    //Anonymous user login to be registered in Firebase
    mAuth = FirebaseAuth.getInstance();
    mCurrentUser = mAuth.getCurrentUser(); // save the UID of the user in users in Firebase without having to log in

    final String UID = mCurrentUser.getUid();
    DatabaseReference currentUserDb = FirebaseDatabase.getInstance().getReference().child("Users").child("UID");
    currentUserDb.setValue(UID); //save the User UID to the Firebase Realtime database



    // Calling to the AdMob API to add advertisements to the banner in the main view.Gotta make that dough
    // Change this to big cards in the future
    final AdView adView = findViewById(R.id.adView);

    final AdRequest adRequest = new AdRequest.Builder()
            //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();

Screenshot to Firebase Authentication

我从logcat收到错误:

W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
I/FirebaseCrashlytics: Initializing Crashlytics 17.0.0
I/FirebaseInitProvider: FirebaseApp initialization successful
I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
V/FA: onActivityCreated
W/rawesome.metim: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
    Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
V/FA: App measurement disabled via the init parameters
I/FA: App measurement initialized, version: 28000
    To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
    To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.superawesome.metime
D/FA: Debug-level message logging enabled
V/FA: Detected application was in foreground
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.superawesome.metime, PID: 21746
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.superawesome.metime/com.superawesome.metime.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3341)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2045)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7478)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
        at com.superawesome.metime.MainActivity.onCreate(MainActivity.java:118)
        at android.app.Activity.performCreate(Activity.java:7989)
        at android.app.Activity.performCreate(Activity.java:7978)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3316)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2045) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7478) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941) 
V/FA: Connecting to remote service
D/FA: Event not sent since app measurement is disabled

com.superawesome.metime.MainActivity.onCreate(MainActivity.java:118) --> final String UID = mCurrentUser.getUid();

我已经尝试解决这个问题超过一个星期了,没有成功

编辑:

我知道我可以添加侦听器来查看用户是否匿名登录。围绕此问题的整个问题是根本不再登录用户。

Edit2:

从logcat:

2020-05-30 12:39:53.655 23257-23297/com.superawesome.metime I/DynamiteModule: Selected remote version of com.google.android.gms.ads.dynamite, version >= 21600
2020-05-30 12:39:53.658 23257-23297/com.superawesome.metime V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
2020-05-30 12:39:53.770 23257-23311/com.superawesome.metime I/TetheringManager: registerTetheringEventCallback:com.superawesome.metime
2020-05-30 12:39:53.818 23257-23303/com.superawesome.metime W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2020-05-30 12:39:54.025 23257-23303/com.superawesome.metime I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
2020-05-30 12:39:54.076 23257-23257/com.superawesome.metime I/FirebaseCrashlytics: Initializing Crashlytics 17.0.0
2020-05-30 12:39:54.220 23257-23257/com.superawesome.metime I/FirebaseInitProvider: FirebaseApp initialization successful
2020-05-30 12:39:54.332 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-05-30 12:39:54.342 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-05-30 12:39:54.362 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2020-05-30 12:39:54.527 23257-23315/com.superawesome.metime V/FA: App measurement disabled via the init parameters
2020-05-30 12:39:55.234 23257-23315/com.superawesome.metime I/FA: App measurement initialized, version: 28000
2020-05-30 12:39:55.247 23257-23315/com.superawesome.metime I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2020-05-30 12:39:55.267 23257-23315/com.superawesome.metime I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.superawesome.metime
2020-05-30 12:39:55.274 23257-23315/com.superawesome.metime D/FA: Debug-level message logging enabled
2020-05-30 12:39:57.009 23257-23315/com.superawesome.metime V/FA: Detected application was in foreground
2020-05-30 12:39:57.995 23257-23315/com.superawesome.metime V/FA: Connecting to remote service
2020-05-30 12:40:23.846 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval
2020-05-30 12:41:23.931 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval
2020-05-30 12:42:54.030 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval

0 个答案:

没有答案