Firebase unable to reconnect after exiting Doze Mode - firebase

Overview
I'm using Flutter with Firebase. After the phone/app enters Doze Mode, Firebase needs a few minutes (too long!) to reconnect. It took me weeks to find how to reproduce this issue.
Steps to reproduce:
Open a Flutter app and select a screen where you can call Firebase with a click of a button
Enter Androids' Doze Mode (Lock the screen, run adb shell dumpsys battery unplug, and then run adb shell dumpsys deviceidle force-idle)
After a few seconds/minutes, under the "Run" tab, the following will appear:
Stream closed with status: Status{code=UNAVAILABLE, description=Keepalive failed. The connection is likely gone, cause=null}.
and
[{0}] Failed to resolve name. status={1}
Now, unlock your phone and try to make a Firebase query
For me, the following error appears 8 out of 10 times. The connection will re-establish after hitting the "Retry" button, but only after a few minutes which is, of course, too late.
W/XXX.XXXXXXX(14214): Accessing
hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J
(greylist,core-platform-api, linking, allowed)
W/XXX.XXXXXXX(14214): Accessing hidden method
Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V
(greylist, linking, allowed) W/Firestore(14214): (22.0.1)
[WatchStream]: (72436f2) Stream closed with status:
Status{code=UNAVAILABLE, description=Unable to resolve host
firestore.googleapis.com, cause=java.lang.RuntimeException:
java.net.UnknownHostException: Unable to resolve host
"firestore.googleapis.com": No address associated with hostname
W/Firestore(14214): at
io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:436)
W/Firestore(14214): at
io.grpc.internal.DnsNameResolver$Resolve.resolveInternal(DnsNameResolver.java:272)
W/Firestore(14214): at
io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:228)
W/Firestore(14214): at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/Firestore(14214): at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/Firestore(14214): at java.lang.Thread.run(Thread.java:919)
W/Firestore(14214): Caused by: java.net.UnknownHostException: Unable
to resolve host "firestore.googleapis.com": No address associated with
hostname W/Firestore(14214): at
java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
W/Firestore(14214): at
java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
W/Firestore(14214): at
java.net.InetAddress.getAllByName(InetAddress.java:1152)
W/Firestore(14214): at
io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:646)
W/Firestore(14214): at
io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:404)
W/Firestore(14214): ... 5 more W/Firestore(14214): Caused by:
android.system.GaiException: android_getaddrinfo failed: EAI_NODATA
(No address associated with hostname) W/Firestore(14214): at
libcore.io.Linux.android_getaddrinfo(Native Method)
W/Firestore(14214): at
libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
W/Firestore(14214): at
libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200)
W/Firestore(14214): at
libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
W/Firestore(14214): at
java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
W/Firestore(14214): ... 9 more W/Firestore(14214): }.
W/XXX.XXXXXXX(14214): Accessing hidden method
Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J
(greylist,core-platform-api, linking, allowed) I/flutter (14214):
MyDatabase | getDatabaselData |
[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.
The caught exception is: MyDatabase | getDatabaselData | [cloud_firestore/unavailable] The service is currently unavailable.
Pubspec.yaml
cloud_firestore: ^0.14.1+3
firebase_storage: ^4.0.1
firebase_core: ^0.5.0+1
firebase_auth: ^0.18.3

Edit 2: At the moment of writing this edit, there is a commit pending on FlutterFire git (but not yet published). So the solution will be to update to the latest Firebase_Core. It is also possible to fix it manually in Firebase_Core package > gradle.properties > change FirebaseSDKVersion=28.0.1 to FirebaseSDKVersion=28.1.0.
Edit: The issue still persists if the phone enters the state naturally (6 hours of complete inactivity). It seems this issue must be fixed inside FirebaseSDK and so far it hasn't been: https://github.com/FirebaseExtended/flutterfire/issues/4305
Old answer:
I see many people strugling with this, and I have finally found the solution.
It seems Firebase is mostly wasting time on the previous (dis)connection rather than the new connection. So what I did, is disconnecting Firebase whenever the app goes to the background, and reconnecting it upon resuming. In this case, a new connection is established within seconds.
Here is the code; create a life cycle manager class (observer) and wrap it around your MaterialApp. Try-Catch is probably not necessary, but I will be pushing to production tomorrow so it's just a precaution.
lifecycle_manager.dart
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class LifecycleManager extends StatefulWidget {
final Widget child;
LifecycleManager({Key key, this.child}) : super(key: key);
#override
_LifecycleManagerState createState() => _LifecycleManagerState();
}
class _LifecycleManagerState extends State<LifecycleManager> with WidgetsBindingObserver {
#override
Widget build(BuildContext context) {
return widget.child;
}
#override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
#override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
try {
if (state != AppLifecycleState.resumed) FirebaseFirestore.instance.disableNetwork();
else FirebaseFirestore.instance.enableNetwork();
} catch (error) {
print('LifecycleManager | didChangeAppLifecycleState | ' + error.toString());
}
}
}
main.dart
import 'lifecycle_manager.dart';
LifecycleManager(child: MaterialApp());
(I have also updated all my dependencies, but that didn't solve the problem)

Delete the application from the emulator.
Install the application.
Delete collection from firebase.
Run the code again.
This solved my problem without any changes to my versions.
Pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
get_it: ^1.0.3+2
provider: ^5.0.0
cloud_firestore: ^0.12.9+4
firebase_auth: 0.14.0+5
Usage
class MainPage extends StatefulWidget {
const MainPage({Key key}) : super(key: key);
#override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
final Firestore _firestore = Firestore.instance;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("First Page"),
),
body: Center(
child: Column(
children: [
RaisedButton(
child: Text("Add Data"),
color: Colors.deepPurple,
onPressed: _addData,
)
],
),
),
);
}
void _addData() {
Map<String, dynamic> addUser = Map();
addUser["name"] = "name1";
addUser["surname"] = "surname1";
_firestore
.collection("users")
.document("nameandsurname")
.setData(addUser)
.then((value) => debugPrint("user added"));
}
}

Related

Capture cloud firestore document snapshot error in Flutter

I am trying to capture the error thrown by firstore plugin in flutter when listening to document snapshots. The error is thrown in the debug logs but I cannot access it on catch error or handle error. Is this an enhancement needed for the plugin or is there a way?
Error in debug
I/System.out(16041): com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
Here is my code, I tried a number of ways but it didn't work
_getUserCollection.document(uid).snapshots();
_getUserCollection.document(uid).snapshots().handleError((onError) {
print(onError.toString());
});
try {
_getUserCollection.document(uid).snapshots();
} catch (e) {
print(e);
}
try {
_getUserCollection.document(uid).snapshots();
} on PlatformException catch (e) {
print(e.toString());
}
_getUserCollection.document(uid).snapshots().listen((event) {
print('here on listen');
}, onError: (e) {
print('on error $e');
});
"Missing or insufficient permissions" means that your query violated one of your security rules. You will need to examine those rules, and make sure they allow the query you intend to perform.
There is plenty of documentation for security rules, and it's necessary to understand how they work in order to work with Firestore effectively from web and mobile clients.
It's not true that you can't catch an error from a Firestore query. You can't use try/catch - you will have to pass an error handler to listen().
I was having the same issue. PERMISSION_DENIED was coming out in the logs but I wanted to catch the error myself so that I could display it to the user. I found this issue on GitHub:
Firebase - native error messages not provided issue
It states that a lot of work has been done to improve the error handling in Firebase. So I spent yesterday upgrading my app to the latest version of firebase_auth (0.18.0 at the time of writing) and I can now catch and handle the PERMISSION_DENIED error like this:
return StreamBuilder<List<DistanceDocSnapshot>>(
stream: _eventStream,
builder: (BuildContext context,
AsyncSnapshot<List<DistanceDocSnapshot>> snapshot) {
if (snapshot.hasError) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Error retrieving events: ${snapshot.error.toString()}',
style: TextStyle(fontSize: 20.0),
textAlign: TextAlign.center,
),
);
}
if (snapshot.hasData) {
// Handle data as desired
}
}
);
This can be seen working in the following screenshot Screenshot of error on my app (I had to provide a link to the screenshot because I don't have enough rep to embed images yet)
My code is laid out differently to yours but I think yours will start working as desired if you just upgrade your firebase_auth version.

Firebase Firestore is failing over wifi on physical device with error: Could not reach Cloud Firestore backend

When trying to get a document from Firestore, if the device is connected through Wifi the connection fails with the following error message:
W/Firestore( 4903): (21.4.3) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
W/Firestore( 4903): 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.
To Reproduce
Usually, the error happens when running in a Physical device.
I created a small app to be able to reproduce the errors with minimal interference from the rest of my code. See the code below.
When you hit run on the debugger (I'm using VSCode) and then I click on the (+) button to make the request to Firestore, it stays trying for a few seconds (you'll see the progress indicator no the test app) and then the call snapshot = await docRef.get() fails with the following error message:
PlatformException(Error performing get, Failed to get document because the client is offline., null)
Then, if you turn the wifi off, the request works perfectly. And the content of the document retrieved from Firestore is present in the screen:
Now if you turn the wifi again, the request works. Sometimes the data is retrieved from the server and other from the cache.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Firestore Network Bug',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _loading = false;
Map<String, dynamic> _firebaseDocument;
String _firebaseError;
String _source;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Firestore Network Bug"),
),
body: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text('Tap the (+) button to try to read from Firestore...',
style: TextStyle(fontSize: 20)),
_showProgress(),
_showResults(),
_showErrors(),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _readFromFirebase,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
Widget _showProgress() {
return Padding(
padding: const EdgeInsets.only(top: 12.0),
child: Container(
height: 6.0,
child: (_loading) ? LinearProgressIndicator() : Container(),
),
);
}
Widget _showResults() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 12.0),
Text("Result:"),
Container(
height: 150,
padding: const EdgeInsets.all(16),
color: Colors.blue[100],
child: (_firebaseDocument != null)
? Text("From $_source: \n\n" + _firebaseDocument?.toString(),
style: TextStyle(fontSize: 16))
: Container(),
),
],
);
}
Widget _showErrors() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 12.0),
Text("Errors:"),
Container(
height: 150,
padding: const EdgeInsets.all(16),
color: Colors.red[100],
child: (_firebaseError != null)
? Text(_firebaseError?.toString(), style: TextStyle(fontSize: 16))
: Container(),
),
],
);
}
void _readFromFirebase() async {
setState(() {
_loading = true;
_firebaseDocument = null;
_firebaseError = null;
});
DocumentReference docRef =
Firestore.instance.document("myCollection/myDocument");
DocumentSnapshot snapshot = await docRef.get().catchError(
(onError) {
setState(() {
_loading = false;
_firebaseDocument = null;
_firebaseError = onError.toString();
});
},
);
if (_firebaseError != null) return;
_source = (snapshot.metadata.isFromCache) ? "cache" : "server";
if (snapshot.exists) {
setState(() {
_loading = false;
_firebaseDocument = snapshot.data;
});
print("Document found!");
print("- ${_firebaseDocument.toString()}");
} else {
print("Document not found!");
}
}
}
Expected behavior
Since the device has perfect connectivity over wifi, it was excepted that the request worked fine and the document was retrieved from the server.
Additional context
On the emulator, everything works perfectly.
I tested in the following emulator configurations: Pixel 4 API 29, Pixel 5 API 25, Pixel 3 API 29.
The physical devices I used to test (both failed identically) where: Pixel 4XL (Android 10 QQ3Q.200605.001) and Pixel 3XL (Android 10 QQ2A.200305.002).
Flutter doctor
[✓] Flutter (Channel stable, v1.17.3, on Mac OS X 10.15.4 19E287, locale en-US)
• Flutter version 1.17.3 at /Users/mlemos/Documents/flutter
• Framework revision b041144f83 (8 days ago), 2020-06-04 09:26:11 -0700
• Engine revision ee76268252
• Dart version 2.8.4
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/mlemos/Library/Android/sdk
• Platform android-30, 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-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.5, Build version 11E608c
• CocoaPods version 1.9.1
[!] Android Studio (version 4.0)
• 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-6222593)
[✓] VS Code (version 1.46.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.11.0
[✓] Connected device (2 available)
• Pixel 4 XL • 99201FFBA000KF • android-arm64 • Android 10 (API 29)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)
! Doctor found issues in 1 category.
pubspec.yaml
name: firestore_network_bug
description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
firebase_analytics: ^5.0.14
cloud_firestore: ^0.13.6
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
/build.gradle
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Application specific configuration (dependencies)
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
/app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
// Application specific configuration (plugins)
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.example.firestore_network_bug"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// Application specific configuration (multidex)
multiDexEnabled true
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Application specific configuration (dependencies)
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
implementation 'com.google.firebase:firebase-firestore:21.4.3'
}
Here is the debug console output:
Over Wifi - When the error happens
Please note that, over Wifi, Crashlytics also fails.
Launching lib/main.dart on Pixel 4 XL in debug mode...
✓ Built build/app/outputs/apk/debug/app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:54122/cahgKkWqnBU=/ws
E/FirebaseCrashlytics(22411): Settings request failed.
E/FirebaseCrashlytics(22411): java.io.InterruptedIOException: timeout
E/FirebaseCrashlytics(22411): at okhttp3.RealCall.timeoutExit(RealCall.java:107)
E/FirebaseCrashlytics(22411): at okhttp3.RealCall.execute(RealCall.java:96)
E/FirebaseCrashlytics(22411): at com.google.firebase.crashlytics.internal.network.HttpRequest.execute(com.google.firebase:firebase-crashlytics##17.0.0:129)
E/FirebaseCrashlytics(22411): at com.google.firebase.crashlytics.internal.settings.network.DefaultSettingsSpiCall.invoke(com.google.firebase:firebase-crashlytics##17.0.0:86)
E/FirebaseCrashlytics(22411): at com.google.firebase.crashlytics.internal.settings.SettingsController$1.then(com.google.firebase:firebase-crashlytics##17.0.0:200)
E/FirebaseCrashlytics(22411): at com.google.firebase.crashlytics.internal.settings.SettingsController$1.then(com.google.firebase:firebase-crashlytics##17.0.0:193)
E/FirebaseCrashlytics(22411): at com.google.android.gms.tasks.zzp.run(Unknown Source:2)
E/FirebaseCrashlytics(22411): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/FirebaseCrashlytics(22411): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/FirebaseCrashlytics(22411): at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(com.google.firebase:firebase-crashlytics##17.0.0:60)
E/FirebaseCrashlytics(22411): at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(com.google.firebase:firebase-crashlytics##17.0.0:27)
E/FirebaseCrashlytics(22411): at java.lang.Thread.run(Thread.java:919)
E/FirebaseCrashlytics(22411): Caused by: java.io.IOException: Canceled
E/FirebaseCrashlytics(22411): at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
E/FirebaseCrashlytics(22411): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
E/FirebaseCrashlytics(22411): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
E/FirebaseCrashlytics(22411): at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
E/FirebaseCrashlytics(22411): at okhttp3.RealCall.execute(RealCall.java:92)
E/FirebaseCrashlytics(22411): ... 10 more
W/DynamiteModule(22411): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(22411): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(22411): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
I/ore_network_bu(22411): The ClassLoaderContext is a special shared library.
I/chatty (22411): uid=10227(com.example.firestore_network_bug) AsyncTask #1 identical 1 line
I/ore_network_bu(22411): The ClassLoaderContext is a special shared library.
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->arrayBaseOffset(Ljava/lang/Class;)I (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->copyMemory(JJJ)V (greylist, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->getByte(J)B (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->getByte(Ljava/lang/Object;J)B (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->getLong(J)J (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->putByte(JB)V (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->putByte(Ljava/lang/Object;JB)V (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
W/ore_network_bu(22411): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
W/ore_network_bu(22411): Accessing hidden field Ljava/nio/Buffer;->address:J (greylist, reflection, allowed)
V/NativeCrypto(22411): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 286 native methods...
W/ore_network_bu(22411): Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (greylist, reflection, allowed)
I/ProviderInstaller(22411): Installed default security provider GmsCore_OpenSSL
W/Firestore(22411): (21.4.3) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
W/Firestore(22411):
W/Firestore(22411): 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.
W/DynamiteModule(22411): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(22411): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(22411): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/DynamiteModule(22411): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(22411): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(22411): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/DynamiteModule(22411): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(22411): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(22411): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/DynamiteModule(22411): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(22411): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(22411): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/DynamiteModule(22411): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(22411): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(22411): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/DynamiteModule(22411): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(22411): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(22411): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
Over LTE - When things work fine
Launching lib/main.dart on Pixel 4 XL in debug mode...
✓ Built build/app/outputs/apk/debug/app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:54345/egB1v0JRe6c=/ws
W/DynamiteModule(23529): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(23529): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(23529): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
I/ore_network_bu(23529): The ClassLoaderContext is a special shared library.
I/chatty (23529): uid=10227(com.example.firestore_network_bug) AsyncTask #1 identical 1 line
I/ore_network_bu(23529): The ClassLoaderContext is a special shared library.
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->arrayBaseOffset(Ljava/lang/Class;)I (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->copyMemory(JJJ)V (greylist, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->getByte(J)B (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->getByte(Ljava/lang/Object;J)B (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->getLong(J)J (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->putByte(JB)V (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->putByte(Ljava/lang/Object;JB)V (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
W/ore_network_bu(23529): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
W/ore_network_bu(23529): Accessing hidden field Ljava/nio/Buffer;->address:J (greylist, reflection, allowed)
V/NativeCrypto(23529): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 286 native methods...
W/ore_network_bu(23529): Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (greylist, reflection, allowed)
I/ProviderInstaller(23529): Installed default security provider GmsCore_OpenSSL
W/ore_network_bu(23529): Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (greylist, reflection, allowed)
W/ore_network_bu(23529): Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (greylist, JNI, allowed)
W/ore_network_bu(23529): Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (greylist, reflection, allowed)
W/ore_network_bu(23529): Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (greylist,core-platform-api, linking, allowed)
W/ore_network_bu(23529): Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (greylist, linking, allowed)
I/flutter (23529): Document found!
I/flutter (23529): - {date: Timestamp(seconds=1590980400, nanoseconds=0), published: true, title: Hello World!, body: Firebase rocks and Firestore rocks also (when it works).}

IllegalArgumentException: Unsupported value: null while login with twitter

I am trying to login with Twitter when i used dependency firebase_auth:^0.6.6 it was working perfactly and i fetch the user's Profile picture and the Code was
final TwitterLoginResult result = await twitterLogin.authorize();
switch (result.status)
{
case TwitterLoginStatus.loggedIn:
var session = result.session;
FirebaseUser user = await _auth.signInWithTwitter(
authToken: session.token, authTokenSecret: session.secret);
img=user.photoUrl;
}
but i migrated the app to AndroidX and this dependency was not compatible so i used firebase_auth: ^0.14.0+5 and this code was not working so i change the code to
final TwitterLoginResult result = await twitterLogin.authorize();
switch (result.status) {
case TwitterLoginStatus.loggedIn:
var session = result.session;
final AuthCredential credential =
TwitterAuthProvider.getCredential(authToken: session.token,
authTokenSecret: session.secret);
FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
and this code is not working app is Crashing and showing the error
W/BiChannelGoogleApi(18829): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzak#70a4ccf
W/InputMethodManager(18829): startInputReason = 1
D/FirebaseAuth(18829): Notifying id token listeners about user ( D71yiiEX7ubSon4xxcddKlSydn72 ).
D/FirebaseAuth(18829): Notifying auth state listeners about user ( D71yiiEXccccccccKlSydn72 ).
I/zygote64(18829): Do full code cache collection, code=124KB, data=91KB
I/zygote64(18829): After code cache collection, code=123KB, data=68KB
I/zygote64(18829): Do partial code cache collection, code=123KB, data=68KB
I/zygote64(18829): After code cache collection, code=123KB, data=68KB
I/zygote64(18829): Increasing code cache capacity to 512KB
D/AndroidRuntime(18829): Shutting down VM
E/AndroidRuntime(18829): FATAL EXCEPTION: main
E/AndroidRuntime(18829): Process: com.example.login_app, PID: 18829
E/AndroidRuntime(18829): java.lang.IllegalArgumentException: Unsupported value: null
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294)
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime(18829): at io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope(StandardMethodCodec.java:57)
E/AndroidRuntime(18829): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225)
E/AndroidRuntime(18829): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin$SignInCompleteListener.onComplete(FirebaseAuthPlugin.java:691)
E/AndroidRuntime(18829): at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
E/AndroidRuntime(18829): at android.os.Handler.handleCallback(Handler.java:808)
E/AndroidRuntime(18829): at android.os.Handler.dispatchMessage(Handler.java:101)
E/AndroidRuntime(18829): at android.os.Looper.loop(Looper.java:166)
E/AndroidRuntime(18829): at android.app.ActivityThread.main(ActivityThread.java:7529)
E/AndroidRuntime(18829): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(18829): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
E/AndroidRuntime(18829): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
I/Process (18829): Sending signal. PID: 18829 SIG: 9
Lost connection to device.
Please can someone explain to me how to resolve this problem?
Problem is with login task AND Androidx twitter_login_issue
Add this dependency in your pubspec.yaml file and let me know this working or not?
flutter_twitter_login:
git: git://github.com/eudangeld/flutter_twitter_login.git
Same issue (question) login_issue

flutter_markdown with Firestore image crash

I'm using flutter_markdown: ^0.2.0 and I want to display an image saved on firebase firestorage.
If I try to display the markdown in my flutter widget:
class LessonScreen extends StatelessWidget {
const LessonScreen({this.lesson});
final Lesson lesson;
#override
Widget build(BuildContext context) {
return Scaffold(
body:
MarkdownBody(data: lesson.content));
}
}
My app crash.
I/flutter (25385): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (25385): The following _Exception was thrown resolving an image codec:
I/flutter (25385): Exception: HTTP request failed, statusCode: 403,
I/flutter (25385): https://firebasestorage.googleapis.com/v0/b/appname-db7de.appspot.com/o/image1.PNG?alt=media&token=xxxx
I don't have this problem with other images, but I have it only with the images saved on firestorage.
SOLVED
I have seen that the url that doesn't work is:
alt=media&token=xxxx
instead of
alt=media&token=xxxx
this is the link to flutter_markown repository issue.
I hope this fix will be available sooner or later
HTTP request failed, statusCode: 403 it means auth error.
You should check more detail about firebase store.
It's not about markdown stuff.
I had the same issue the problem was with the permission in the Firebase Storage so I change my Firebase Storage permission.
From
allow read, write: if request.auth != null;
To this
allow read, write;

flutter app crashes when internet gets disconnected while runnig transactions

I have asked a similar question Here.The new problem is that, after the internet address lookup('connected' is printed), but while the transaction is being run if the network is disconnected or when the network is very slow I get a timed out error exception which causes the app to crash.
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
print('connected');
Firestore.instance.runTransaction((transactionshere)async{
DocumentReference reference =
Firestore.instance.collection('One').document('two').collection('three').document('all_').collection('cur').document();
await reference.setData(dataToSend,merge: true);
});
}
} on SocketException catch (_) {
print('not connected');
_scafoldKey.currentState.showSnackBar(
SnackBar(content: Text("There was a problem check your connection"),duration: Duration(seconds: 4),),
);
}
error output:
I/flutter (24149): connected
W/Firestore(24149): (0.6.6-dev) [Firestore]: The behavior for java.util.Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK.
W/Firestore(24149): To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:
W/Firestore(24149):
W/Firestore(24149): FirebaseFirestore firestore = FirebaseFirestore.getInstance();
W/Firestore(24149): FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
W/Firestore(24149): .setTimestampsInSnapshotsEnabled(true)
W/Firestore(24149): .build();
W/Firestore(24149): firestore.setFirestoreSettings(settings);
W/Firestore(24149):
W/Firestore(24149): With this change, timestamps stored in Cloud Firestore will be read back as com.google.firebase.Timestamp objects instead of as system java.util.Date objects. So you will also need to update code expecting a java.util.Date to instead expect a Timestamp. For example:
W/Firestore(24149):
W/Firestore(24149): // Old:
W/Firestore(24149): java.util.Date date = snapshot.getDate("created_at");
W/Firestore(24149): // New:
W/Firestore(24149): Timestamp timestamp = snapshot.getTimestamp("created_at");
W/Firestore(24149): java.util.Date date = timestamp.toDate();
W/Firestore(24149):
W/Firestore(24149): Please audit all existing usages of java.util.Date when you enable the new behavior. In a future release, the behavior will be changed to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.
I/zygote (24149): The ClassLoaderContext is a special shared library.
I/zygote (24149): The ClassLoaderContext is a special shared library.
V/NativeCrypto(24149): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 287 native methods...
D/NetworkSecurityConfig(24149): No Network Security Config specified, using platform default
I/ProviderInstaller(24149): Installed default security provider GmsCore_OpenSSL
W/System (24149): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(24149): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
W/System (24149): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(24149): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
W/System (24149): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(24149): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
W/System (24149): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar

Resources