Flutter how to cancel all FirebaseAuth authStateChanges Subscriptions after hot restart? - firebase

whenever i hot restart the app in debug in Flutter, new Subscriptions keep getting added to FirebaseAuth.instance.authStateChanges().
What I need to know:
How many subscriptions does authStateChanges() already have?
How can i cancel a subscription on that stream (authStateChanges()) if the reference to the subscription is lost due to hot restart?
How can i guarantee, that my subscription is only fired once?
The problem:
Whenever i hot restart the app multiple (n) times, it fires n times. This is undesired. I want to make sure it only gets subscribed once and i want to make sure to cancel any subscription beforehand.
Here's the code i use:
StreamSubscription<User?>? subscription;
void onAuthStateChanged(Function(User?) onAuthStateChanges) async {
if (subscription == null) {
subscription =
FirebaseAuth.instance.authStateChanges().listen(onAuthStateChanges);
} else {
// Please do not subscribe
}
}
I use the following versions:
yaml:
firebase_core: ^1.10.6
firebase_auth: "^3.3.4"
flutter doctor:
Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.18363.1801], locale de-DE)
Android toolchain - develop for Android devices (Android SDK version 31.0.0)
Chrome - develop for the web
Visual Studio - develop for Windows (Visual Studio Community 2019 16.6.2)
Android Studio (version 3.2)
Android Studio (version 2020.3)
VS Code, 64-bit edition (version 1.62.2)
Connected device (4 available)

Related

Google Sign In package's disconnect method call results in error when trying to sign in again using Flutter Firebase

I am using Firebase auth with Flutter and have implemented google sign in using google_sign_in package version ^5.2.3
I noticed that after signing out, when I clicked sign in again the app didn't prompt me to select which of my google accounts I want to sign in it, instead logging me in with the previous account I had used.
After some research I added the following code in sign out flow
await GoogleSignIn().disconnect();
await FirebaseAuth.instance.signOut();
I was able to sign out, but when I tried to log in again, I got an exception with following message
PlatformException (PlatformException(exception, BAD_REQUEST, null, null))
HOWEVER, if I hot restart app, I am able to sign in and also get the prompt to select a google account I want to log in. The google sign in plugin github doesn't allow issue filing so I can't get help here. Help appreciated.
flutter doctor
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v): [√]
Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version
10.0.18362.535], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK
version 30.0.0-rc2)
X cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for
more details.
[√] Chrome - develop for the web
[√] Android Studio (version 3.6)
[√] IntelliJ IDEA Community Edition (version 2018.1)
[!] IntelliJ IDEA Ultimate Edition (version 2016.2)
X This install is older than the minimum recommended version of 2017.1.0.
[√] VS Code, 32-bit edition (version 1.63.2)
[√] Connected device (2 available)
! Doctor found issues in 2 categories.
I leave the answer as a reference for another person who has the same error.
await GoogleSignIn().signOut();
Implementation though icon button:
IconButton(
onPressed: (() async {
await FirebaseAuth.instance.signOut();
await GoogleSignIn().signOut();
}),
icon: const Icon(Icons.exit_to_app)
)

iPhone simulator takes minutes to launch using Xamarin.UITest

I'm trying to automate our Xamarin.Forms project (Android&iOS) and decided to try out Xamarin.UITest for some smoke testing.
I've managed to connect the app and using REPL I've also located the elements we wish to interact with.
The issue:
The test itself works, but when I try to run it, my iPhone simulator either freezes and/or restarts multiple times.
This means going through a simple login flow-test takes up to 5 minutes, where most of that is looking at a frozen simulator not launching my app.
The simulator will eventually launch and connect, although sometimes it appears to be running headless(!?), as my tests go through but I have no simulator open.
My app initializer:
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp.Android.StartApp();
}
//Environment.SetEnvironmentVariable("UITEST_FORCE_IOS_SIM_RESTART", "1");
IApp app = ConfigureApp.iOS
.StartApp(Xamarin.UITest.Configuration.AppDataMode.DoNotClear);
return app;
}
(note I have tried with and without the AppDataMode parameter).
And my setup
IApp app;
Platform platform;
public Tests(Platform platform)
{
this.platform = platform;
}
[SetUp]
public void BeforeEachTest()
{
app = AppInitializer.StartApp(platform);
}
My setup:
MacBook Pro 2020 running Big Sur (11.5.2)
Visual Studio Community 8.10.8
Xcode 12.5.1
Xamarin.Forms 5.0.0.2012
Xamarin.UITest 3.2.0
iPhone simulators tested:
iPhone 12 - iOS 14.4
iPhone 8 - iOS 14.4
iPhone SE (2nd gen) iOS 13.7
As a final note, when running the iOS project normally (just debugging), this behaviour is not observed. The rebooting & freezing only occurs on UITests.

AndroidTV app builds ok and will install but can't be opened. Android 7.1.1 TV

I'm at the bottom of the J curve as far as Android development goes, but I can't even get the demo app to work on my Android TV. I build the TV device blank activity in Android Studio, and it works fine in an emulator. I have a banner(320x180pixels), android.hardware.touchscreen(false), android.software.leanback(true), and LEANBACK_LAUNCHER in the intent.
The APK (which I have signed with V2 and marked as a release) installs with warnings from playprotect (which I can't shut off in this locked-down TV) but cannot be opened. I have sideloaded other APK's via the same method. I have also tried not signing the APK.
The TV is an Axis 1832S running Android 7.1.1. I CAN put it into developer mode if that helps.
Does anyone have any hints, or a simple 'hello world' apk that works that I can try?

Problem with Firebase in SwiftUI macos app. [Running InstanceID on a simulator doesn't have APNS. Use prod profile by default.]

I wanted to run my swiftui app on macos, unfortunately i can still see error That
Running InstanceID on a simulator doesn't have APNS. Use prod
profile by default.
I used the code from firebase messaging docs to initialize firebase messaging and later on I wanted to get instance id token.
While using Xcode I don't get any other errors instead of this which I mentioned. That's why I decided to archive my app and run it independently
outside Xcode. Unfortunately I still can see in console error message about running in simulator. When I run that code on my physical iPhone everything works properly.
Xcode log
Mac console log
Does anyone know what should I change or how should I archive the app properly in order to firebase not detect my app as simulator?

Google Analyitcs with gms version 11.4.0 or higher is not working with instant apps when run on Nought Devices

We want to transfer data from instant app to installed app using Cookie API. Cookie API needs to have a play services version 11.4.0 or more. It works on lollipop, marshmallow and Oreo devices but crashes on Nought devices only showing following exception.
java.lang.NullPointerException: Attempt to invoke interface method 'void android.app.job.IJobScheduler.cancel(int)' on a null object reference.
It crashes when we use GoogleAnalytics.getInstance(getContext()) to get the Google Analytics Instance. But it works on all platforms except Nought.
I believe this is the same as this issue.
If that's the case, then this should fix it.
This is normally fixed in Google Play services for Instant Apps version 2.3. However, when you provision your device with Android Studio, you no longer receive OTA updates. You can check that from the version number (Android Studio provisioned version contains "sdk").
Try uninstalling Google Play services for Instant Apps. Then turn off Instant Apps and turn it on again. It should restore the final version (2.6-release), which contains the fix.
Deploying from the IDE will overwrite it still though.
So once it's updated, you can also remove the forced provision from the Edit Configuration dialog.
This was my issue with Firebase Analytics and I got the same error. So try that out and let me know if it helps.

Resources