Firebase身份验证突然停止工作。

huangapple 未分类评论50阅读模式
英文:

Firebase Authentication suddenly stopped working

问题

我有一个不需要登录的Android应用程序,但我已经启用了匿名登录,以便从Firebase检索userID并将其用于记录特定事件。我有一种感觉,它突然停止从Firebase检索UID。

我尝试解决此问题的方法如下:

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

我的清单:

  1. <!-- 这里是清单的XML代码 -->

我的代码:

  1. // 这里是你的Java代码

从日志中看到的错误:

  1. // 这里是你的错误日志

我已经尝试了一个多星期来解决这个问题,但没有成功。

编辑:

我知道我可以添加监听器来查看用户是否匿名登录。整个问题在于用户根本不再被签入。

从日志中看到的错误:

  1. // 这里是你从日志中看到的错误

编辑2:

从日志中看到的内容:

  1. // 这里是你从日志中看到的内容
英文:

I have an android app that does not require a log in, but I do have Anonymous sign-in enabled so that I can retrieve the userID from Firebase and use it to log specific events. I have the feeling that it just stopped retrieving the UID from Firebase.

What I've done to resolve the issue is the following:

  • updated all the dependencies
  • updated the emulator
  • Installed a new emulator
  • re-added the google services plugin
  • re-added google-services.json file
  • updated Android Manifest
  • I've tried to create a login-activity for the sake of testing, where through a button with an onclicklisterer, the user get's anoynmously logged in.
  • I've doubled checked Local History in Android Studio to see whether big changes were made to the code, not the case. See screenshot
  • Enabled and disabled anonymous login from the Firebase Console.
  • Re-written the entire code based on documentation from Firebase.
  • I've basically tried every solution there is

My Manifest

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  3. xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  4. package=&quot;com.superawesome.metime&quot;&gt;
  5. &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
  6. &lt;application
  7. android:allowBackup=&quot;true&quot;
  8. android:icon=&quot;@mipmap/ic_launcher&quot;
  9. android:label=&quot;@string/wazzup&quot;
  10. android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
  11. android:supportsRtl=&quot;true&quot;
  12. android:theme=&quot;@style/AppTheme&quot;&gt;
  13. &lt;activity android:name=&quot;.Cardview&quot; /&gt;
  14. &lt;activity android:name=&quot;.cardviewactivity&quot; /&gt;
  15. &lt;meta-data
  16. android:name=&quot;com.google.android.gms.ads.APPLICATION_ID&quot;
  17. android:value=&quot;ca-app-pub-xxx&quot; /&gt;
  18. &lt;activity
  19. android:name=&quot;.MainActivity&quot;
  20. android:label=&quot;@string/app_name&quot;&gt;
  21. &lt;intent-filter&gt;
  22. &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  23. &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
  24. &lt;/intent-filter&gt;
  25. &lt;/activity&gt;
  26. &lt;activity
  27. android:name=&quot;com.google.firebase.auth.internal.FederatedSignInActivity&quot;
  28. tools:replace=&quot;android:launchMode&quot;
  29. android:launchMode=&quot;standard&quot; /&gt;
  30. &lt;service
  31. android:name=&quot;.MyFirebaseInstanceIDService&quot;&gt;
  32. &lt;intent-filter&gt;
  33. &lt;action android:name=&quot;com.google.firebase.INSTANCE_ID_EVENT&quot;/&gt;
  34. &lt;/intent-filter&gt;
  35. &lt;/service&gt;
  36. &lt;/application&gt;
  37. &lt;/manifest&gt;

My code:

  1. @Override
  2. public boolean onOptionsItemSelected(@NonNull MenuItem item) {
  3. switch (item.getItemId()) {
  4. case android.R.id.home:
  5. NavUtils.navigateUpFromSameTask(this);
  6. return true; // go back to the first screen
  7. case R.id.cardoverview:
  8. startActivity(new Intent(this, cardviewactivity.class));
  9. return true; //go to the screen where all the swiped right activities are stored
  10. }
  11. return super.onOptionsItemSelected(item);
  12. }
  13. @Override
  14. protected void onStart() {
  15. super.onStart();
  16. mAuth.addAuthStateListener(mAuthListener);
  17. }
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_main);
  22. FirebaseInstanceId.getInstance().getInstanceId()
  23. .addOnCompleteListener(new OnCompleteListener&lt;InstanceIdResult&gt;() {
  24. @Override
  25. public void onComplete(@NonNull Task&lt;InstanceIdResult&gt; task) {
  26. if (!task.isSuccessful()) {
  27. Log.w(&quot;This Tag&quot;, &quot;getInstanceId failed&quot;, task.getException());
  28. return;
  29. } else {
  30. Log.d(&quot;This tag&quot;, &quot;We need this&quot;);
  31. }
  32. }
  33. });
  34. swipeDb = FirebaseDatabase.getInstance().getReference().child(&quot;Users&quot;);
  35. final FirebaseFirestore db = FirebaseFirestore.getInstance();
  36. //Anonymous user login to be registered in Firebase
  37. mAuth = FirebaseAuth.getInstance();
  38. mCurrentUser = mAuth.getCurrentUser(); // save the UID of the user in users in Firebase without having to log in
  39. final String UID = mCurrentUser.getUid();
  40. DatabaseReference currentUserDb = FirebaseDatabase.getInstance().getReference().child(&quot;Users&quot;).child(&quot;UID&quot;);
  41. currentUserDb.setValue(UID); //save the User UID to the Firebase Realtime database
  42. // Calling to the AdMob API to add advertisements to the banner in the main view.Gotta make that dough
  43. // Change this to big cards in the future
  44. final AdView adView = findViewById(R.id.adView);
  45. final AdRequest adRequest = new AdRequest.Builder()
  46. //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
  47. .build();

Screenshot to Firebase Authentication

Error I'm receiving from the logcat:

  1. W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
  2. I/FirebaseCrashlytics: Initializing Crashlytics 17.0.0
  3. I/FirebaseInitProvider: FirebaseApp initialization successful
  4. I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
  5. D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
  6. D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
  7. D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
  8. V/FA: onActivityCreated
  9. W/rawesome.metim: Accessing hidden method Landroid/view/View;-&gt;computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
  10. Accessing hidden method Landroid/view/ViewGroup;-&gt;makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
  11. V/FA: App measurement disabled via the init parameters
  12. I/FA: App measurement initialized, version: 28000
  13. To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
  14. To enable faster debug mode event logging run:
  15. adb shell setprop debug.firebase.analytics.app com.superawesome.metime
  16. D/FA: Debug-level message logging enabled
  17. V/FA: Detected application was in foreground
  18. D/AndroidRuntime: Shutting down VM
  19. E/AndroidRuntime: FATAL EXCEPTION: main
  20. Process: com.superawesome.metime, PID: 21746
  21. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.superawesome.metime/com.superawesome.metime.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method &#39;java.lang.String com.google.firebase.auth.FirebaseUser.getUid()&#39; on a null object reference
  22. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3341)
  23. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485)
  24. at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
  25. at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
  26. at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
  27. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2045)
  28. at android.os.Handler.dispatchMessage(Handler.java:106)
  29. at android.os.Looper.loop(Looper.java:223)
  30. at android.app.ActivityThread.main(ActivityThread.java:7478)
  31. at java.lang.reflect.Method.invoke(Native Method)
  32. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
  33. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
  34. Caused by: java.lang.NullPointerException: Attempt to invoke virtual method &#39;java.lang.String com.google.firebase.auth.FirebaseUser.getUid()&#39; on a null object reference
  35. at com.superawesome.metime.MainActivity.onCreate(MainActivity.java:118)
  36. at android.app.Activity.performCreate(Activity.java:7989)
  37. at android.app.Activity.performCreate(Activity.java:7978)
  38. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
  39. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3316)
  40. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485)&#160;
  41. at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)&#160;
  42. at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)&#160;
  43. at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)&#160;
  44. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2045)&#160;
  45. at android.os.Handler.dispatchMessage(Handler.java:106)&#160;
  46. at android.os.Looper.loop(Looper.java:223)&#160;
  47. at android.app.ActivityThread.main(ActivityThread.java:7478)&#160;
  48. at java.lang.reflect.Method.invoke(Native Method)&#160;
  49. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)&#160;
  50. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)&#160;
  51. V/FA: Connecting to remote service
  52. D/FA: Event not sent since app measurement is disabled
  53. com.superawesome.metime.MainActivity.onCreate(MainActivity.java:118) --&gt; final String UID = mCurrentUser.getUid();

I've been trying to resolve this issue for over a week now with no success

Edit:

I know I can add listeners to see if the user is anonymously signed in or not. The whole problem around this is that the user is not being signed in anymore at all.

Edit2:

From logcat:

  1. 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 &gt;= 21600
  2. 2020-05-30 12:39:53.658 23257-23297/com.superawesome.metime V/DynamiteModule: Dynamite loader version &gt;= 2, using loadModule2NoCrashUtils
  3. 2020-05-30 12:39:53.770 23257-23311/com.superawesome.metime I/TetheringManager: registerTetheringEventCallback:com.superawesome.metime
  4. 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.
  5. 2020-05-30 12:39:54.025 23257-23303/com.superawesome.metime I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
  6. 2020-05-30 12:39:54.076 23257-23257/com.superawesome.metime I/FirebaseCrashlytics: Initializing Crashlytics 17.0.0
  7. 2020-05-30 12:39:54.220 23257-23257/com.superawesome.metime I/FirebaseInitProvider: FirebaseApp initialization successful
  8. 2020-05-30 12:39:54.332 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
  9. 2020-05-30 12:39:54.342 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
  10. 2020-05-30 12:39:54.362 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
  11. 2020-05-30 12:39:54.527 23257-23315/com.superawesome.metime V/FA: App measurement disabled via the init parameters
  12. 2020-05-30 12:39:55.234 23257-23315/com.superawesome.metime I/FA: App measurement initialized, version: 28000
  13. 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
  14. 2020-05-30 12:39:55.267 23257-23315/com.superawesome.metime I/FA: To enable faster debug mode event logging run:
  15. adb shell setprop debug.firebase.analytics.app com.superawesome.metime
  16. 2020-05-30 12:39:55.274 23257-23315/com.superawesome.metime D/FA: Debug-level message logging enabled
  17. 2020-05-30 12:39:57.009 23257-23315/com.superawesome.metime V/FA: Detected application was in foreground
  18. 2020-05-30 12:39:57.995 23257-23315/com.superawesome.metime V/FA: Connecting to remote service
  19. 2020-05-30 12:40:23.846 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval
  20. 2020-05-30 12:41:23.931 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval
  21. 2020-05-30 12:42:54.030 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval

huangapple
  • 本文由 发表于 2020年5月29日 23:28:23
  • 转载请务必保留本文链接:https://java.coder-hub.com/62089457.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定