firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.68k stars 3.97k forks source link

πŸ› [cloud_firestore] Add new doc to firebase fails on Android API 26, Samsung S7 #4253

Closed apetroaeiandrei closed 3 years ago

apetroaeiandrei commented 3 years ago

Bug report

Describe the bug I get an error when trying to add a new document to firebase on
β€’ SM G930F (mobile) β€’ ce06160639360e0d01 β€’ android-arm64 β€’ Android 8.0.0 (API 26) However this is internal and I can't catch it with a try/catch. It works perfectly fine on iOS and on β€’ Android SDK built for x86 (mobile) β€’ emulator-5554 β€’ android-x86 β€’ Android 10 (API 29) (emulator)

The error is: W/Firestore( 2475): (21.7.1) [WriteStream]: (4b960be) Stream closed with status: Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}.

Steps to reproduce

Steps to reproduce the behavior:

  1. Write a new doc to firebase

Expected behavior

Writing a new document is successful.


Additional context

Auth is successful, setting a new doc fails. This is the code, the function never returns.

final auth.FirebaseAuth _auth = auth.FirebaseAuth.instance;
final _db = FirebaseFirestore.instance;
Future<bool> register(String email, String password, String company) async {
    try {
      final auth.User user = (await _auth.createUserWithEmailAndPassword(
              email: email, password: password))
          .user;
      print("Register success for " + user.uid);
      userId = user.uid;
      var users = _db.collection(DB_COLLECTION_USERS).doc(userId);
      await users.set({
        DB_FIELD_USER_EMAIL: email,
        DB_FIELD_USER_COMPANY: company,
        DB_FIELD_USER_DEVICES: "devices",
        DB_FIELD_USER_ADDRESS: "address"
      });
      SharedPreferences prefs = await SharedPreferences.getInstance();
      await prefs.setString(Constants.PREF_KEY_BUSINESS_NAME, company);
      await prefs.setString(Constants.PREF_KEY_ADDRESS, "");
      await prefs.setString(Constants.PREF_KEY_EMAIL, email);
    } on Exception catch (e) {
      print("Register error " + e.toString());

      return false;
    }
    return true;
  }

Flutter doctor

The plugins are correctly installed, flutter doctor just doesn't see them.

Click To Expand ``` [βœ“] Flutter (Channel stable, 1.22.4, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-RO) β€’ Flutter version 1.22.4 at /Users/aapetroaei/personal/flutter β€’ Framework revision 1aafb3a8b9 (2 weeks ago), 2020-11-13 09:59:28 -0800 β€’ Engine revision 2c956a31c0 β€’ Dart version 2.10.4 [βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.2) β€’ Android SDK at /Users/aapetroaei/Library/Android/sdk β€’ Platform android-29, build-tools 29.0.2 β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 12.1) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Xcode 12.1, Build version 12A7403 β€’ CocoaPods version 1.9.3 [!] Android Studio (version 4.1) β€’ Android Studio at /Applications/Android Studio.app/Contents βœ— Flutter plugin not installed; this adds Flutter specific functionality. βœ— Dart plugin not installed; this adds Dart specific functionality. β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [βœ“] Connected device (3 available) β€’ SM G930F (mobile) β€’ ce06160639360e0d01 β€’ android-arm64 β€’ Android 8.0.0 (API 26) β€’ Android SDK built for x86 (mobile) β€’ emulator-5554 β€’ android-x86 β€’ Android 10 (API 29) (emulator) β€’ Andrei’s iPhone (mobile) β€’ 00008020-001938C13C30003A β€’ ios β€’ iOS 13.5.1 ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` dependencies: - assets_audio_player 2.0.13+1 [flutter rxdart uuid http path_provider assets_audio_player_web] - cloud_firestore 0.14.3+1 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web] - cupertino_icons 0.1.3 - excel 1.1.5 [archive xml] - firebase_analytics 6.2.0 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface] - firebase_auth 0.18.3+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter] - firebase_core 0.5.2+1 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math] - flutter_mailer 0.4.3 [flutter] - flutter_platform_widgets 0.70.2 [flutter] - intl 0.16.1 [path] - path_provider 1.6.24 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - permission_handler 5.0.1+1 [flutter meta permission_handler_platform_interface] - qr_code_scanner 0.0.13 [flutter] - random_string 2.1.0 - shared_preferences 0.5.12+4 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows] - sqflite 1.3.2+1 [flutter sqflite_common path] - url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows] - wakelock 0.1.4+2 [flutter] dev dependencies: - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] transitive dependencies: - archive 2.0.13 [crypto args path] - args 1.6.0 - assets_audio_player_web 2.0.13+1 [flutter flutter_web_plugins] - async 2.5.0-nullsafety.1 [collection] - boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner] - characters 1.1.0-nullsafety.3 - charcode 1.2.0-nullsafety.1 - clock 1.1.0-nullsafety.1 - cloud_firestore_platform_interface 2.2.0 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.2.1+1 [flutter flutter_web_plugins http_parser meta firebase_core firebase_core_web cloud_firestore_platform_interface js] - collection 1.15.0-nullsafety.3 - convert 2.1.1 [charcode typed_data] - crypto 2.1.5 [collection convert typed_data] - fake_async 1.2.0-nullsafety.1 [clock collection] - ffi 0.1.3 - file 5.2.1 [intl meta path] - firebase 7.3.2 [http http_parser js] - firebase_analytics_platform_interface 1.0.3 [flutter meta] - firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta] - firebase_auth_platform_interface 2.1.3 [flutter meta firebase_core plugin_platform_interface] - firebase_auth_web 0.3.2+1 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js] - firebase_core_platform_interface 2.1.0 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.1+1 [firebase_core_platform_interface flutter flutter_web_plugins meta js] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - http 0.12.2 [http_parser path pedantic] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - js 0.6.2 - matcher 0.12.10-nullsafety.1 [stack_trace] - meta 1.3.0-nullsafety.3 - path 1.8.0-nullsafety.1 - path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+6 [flutter] - path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface] - path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32] - pedantic 1.9.2 [meta] - permission_handler_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - petitparser 3.1.0 [meta] - platform 2.2.1 - plugin_platform_interface 1.0.3 [meta] - process 3.0.13 [file intl meta path platform] - quiver 2.1.5 [matcher meta] - rxdart 0.24.1 - shared_preferences_linux 0.0.2+4 [file flutter meta path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 0.0.1+11 [shared_preferences_platform_interface flutter] - shared_preferences_platform_interface 1.0.4 [meta flutter] - shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta] - shared_preferences_windows 0.0.1+3 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows] - sky_engine 0.0.99 - source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph] - sqflite_common 1.0.2+1 [synchronized path meta] - stack_trace 1.10.0-nullsafety.1 [path] - stream_channel 2.1.0-nullsafety.1 [async] - string_scanner 1.1.0-nullsafety.1 [charcode source_span] - synchronized 2.2.0+2 - term_glyph 1.2.0-nullsafety.1 - test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.0-nullsafety.3 [collection] - url_launcher_linux 0.0.1+4 [flutter] - url_launcher_macos 0.0.1+9 [flutter] - url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface] - url_launcher_web 0.1.5+1 [url_launcher_platform_interface flutter flutter_web_plugins meta] - url_launcher_windows 0.0.1+3 [flutter] - uuid 2.2.2 [crypto convert] - vector_math 2.1.0-nullsafety.3 - win32 1.7.4 [ffi] - xdg_directories 0.1.2 [meta path process] - xml 4.5.1 [collection convert meta petitparser] ```

TahaTesser commented 3 years ago

Hi @apetroaeiandrei Are you only experiencing this issue on this device? Did you try any other physical device? I can't reproduce the issue on a physical device or emulator running API 30 and API 26

Here is a clean reproducible code sample, please make sure you've stable internet connection your device and try again or different device

code sample ```bash import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); FirebaseApp app = await Firebase.initializeApp(); assert(app != null); runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Material App', theme: ThemeData.dark(), home: Home(), ); } } class Home extends StatelessWidget { final FirebaseAuth _auth = FirebaseAuth.instance; final _db = FirebaseFirestore.instance; Future register(String email, String password, String company) async { try { final User user = (await _auth.createUserWithEmailAndPassword( email: email, password: password)) .user; print("Register success for " + user.uid); var id = user.uid; var users = _db.collection('users').doc(id); await users.set({ 'email': email, 'company': company, 'user_devices': "devices", 'user_address': "address" }); } on Exception catch (e) { print("Register error " + e.toString()); return false; } return true; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Material App Bar'), ), body: Center( child: Container( child: Text('Hello World'), ), ), floatingActionButton: FloatingActionButton( child: Icon(Icons.add), onPressed: () { register('ironman@marvel.com', '12345678', 'Marvel'); }, ), ); } } ```
flutter doctor -v ```bash [βœ“] Flutter (Channel stable, 1.22.4, on macOS 11.0.1 20B29 darwin-x64, locale en-GB) β€’ Flutter version 1.22.4 at /Users/tahatesser/Code/flutter_stable β€’ Framework revision 1aafb3a8b9 (2 weeks ago), 2020-11-13 09:59:28 -0800 β€’ Engine revision 2c956a31c0 β€’ Dart version 2.10.4 [βœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.2) β€’ Android SDK at /Users/tahatesser/Code/sdk β€’ Platform android-30, build-tools 30.0.2 β€’ ANDROID_HOME = /Users/tahatesser/Code/sdk β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 12.2) β€’ Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer β€’ Xcode 12.2, Build version 12B45b β€’ CocoaPods version 1.10.0 [!] Android Studio (version 4.1) β€’ Android Studio at /Applications/Android Studio.app/Contents βœ— Flutter plugin not installed; this adds Flutter specific functionality. βœ— Dart plugin not installed; this adds Dart specific functionality. β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [βœ“] VS Code (version 1.51.1) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension version 3.16.0 [βœ“] Connected device (3 available) β€’ RMX2001 (mobile) β€’ EUYTFEUSQSRGDA6D β€’ android-arm64 β€’ Android 10 (API 29) β€’ Android SDK built for x86 (mobile) β€’ emulator-5554 β€’ android-x86 β€’ Android 8.0.0 (API 26) (emulator) β€’ iPhone 12 (mobile) β€’ BBCEDCF6-A80B-49DC-86EE-C9B542A9AD1B β€’ ios β€’ com.apple.CoreSimulator.SimRuntime.iOS-14-2 (simulator) ! Doctor found issues in 1 category. ```
apetroaeiandrei commented 3 years ago

It works on emulators on my side as well. This device seems to be problematic. It seems that I cannot do any Firebase operation on it. I can also see this error:

W/Firestore(10937): (21.7.1) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
W/Firestore(10937): 
W/Firestore(10937): This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
E/flutter (10937): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.
E/flutter (10937): #0      MethodChannelDocumentReference.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_document_reference.dart:80:7)
E/flutter (10937): <asynchronous suspension>
E/flutter (10937): #1      DocumentReference.get (package:cloud_firestore/src/document_reference.dart:63:36)
E/flutter (10937): #2      LoginManager.fetchUser (package:me_business/managers/LoginManager.dart:33:10)
TahaTesser commented 3 years ago

Hi @apetroaeiandrei Can you please uninstall the app and run it again, with a stable internet connection Thank you

apetroaeiandrei commented 3 years ago

I did a fresh install, phone restart. Firebase Auth works, Internet is stable. Same issue

Salakar commented 3 years ago

Closing in favour of #5546