When I try Firebase Firestore on my Android device, the error below is occurred.
[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.
This doesn't happen when I try with emulator even same code.
What I doing
Updated version of firebase packages.
firebase_core: ^1.10.0
firebase_auth: ^3.1.4
cloud_firestore: ^3.1.0
Using FutureBuilder to get fields.
In my StatefulWidget;
#override
Widget build(BuildContext context) {
myInterstitial.load();
return FutureBuilder(
future: FirebaseFirestore.instance
.collection("users")
.doc(FirebaseAuth.instance.currentUser!.uid)
.get(),
builder:
(BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
return Text(snapshot.error.toString());
}
if (snapshot.hasData && !snapshot.data!.exists) {
FirebaseAuth.instance.signOut();
return const Text("Document does not exist ");
}
if (snapshot.connectionState == ConnectionState.done) {
.............
I don't know why but snapshot.hasError is alaways true, and snapshot.error.toString() returns error above.
I didn't change any code but it works on emulator. However the build (build with $ flutter build appbundle --no-sound-null-safety, $ flutter build apk --no-sound-null-safety and '$ flutter run --no-sound-null-safety') doesn't work better.
The biggest mystery is that everything works correctly in the emulator.
How can I solve this?
flutter doctor -v
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 400608f101 (8 weeks ago), 2021-09-15 15:50:26 -0700
• Engine revision 1d521d89d8
• Dart version 2.15.0 (build 2.15.0-82.2.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at D:\Android
• Platform android-31, build-tools 29.0.3
• Java binary at: D:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.2)
• Android Studio at D:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
[√] VS Code (version 1.62.2)
• VS Code at C:\Users\yukik\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.28.0
[√] Connected device (4 available)
• Pixel 5a (mobile) • 16121JECB02429 • android-arm64 • Android 12 (API 31)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69
• Edge (web) • edge • web-javascript • Microsoft Edge 95.0.1020.44
• No issues found!
I've been through this recently in a React Native project with Android emulator.
The only thing that solved was to delete the emulator device and creating another.
I was experience a similar issue ,
firebase/firestore (while performing get , set and other operations) on emulator , everything was working fine on an actual android device but not on android emulator,
what I did to fix was , changed my android studio to 2021 patch version It fixed the error and everything started working .
Hope it helps someone :)
Related
I'm currently building an app, but it crashes on startup. I've decided tot replace the main.dart code with the most basic default Flutter code, so I can paste codes from the original main.dart file in order to find out what causes the app to crash on startup.
main.dart:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Flutter Demo'),
),
body: Center(
child: Text('Hello World'),
),
),
);
}
}
But when running I get the following error message:
√ Built build\app\outputs\flutter-apk\app-debug.apk.
D/FlutterLocationService(10600): Creating service.
D/FlutterLocationService(10600): Binding to location service.
Lost connection to device.
As you can see, I have not even mentioned geolocator or location plugin in the main.dart but it still crashes with D/FlutterLocationService. How does that even work? It has the same error message as the orginal main.dart. How can I solve this whole predicament?
flutter doctor -v:
[!] Flutter (Channel unknown, 3.3.8, on Microsoft Windows [Version 10.0.22000.1335], locale en-US)
! Flutter version 3.3.8 on channel unknown at C:\Users\DELL\Downloads\flutter_windows_2.10.2-stable\flutter
! Upstream repository unknown
• Framework revision 52b3dc25f6 (8 weeks ago), 2022-11-09 12:09:26 +0800
• Engine revision 857bd6b74c
• Dart version 2.18.4
• DevTools version 2.15.0
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at C:\Users\DELL\AppData\Local\Android\sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.1)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.2.32516.85
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2021.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
[√] VS Code (version 1.74.2)
• VS Code at C:\Users\DELL\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.56.0
[√] Connected device (4 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 12 (API 32) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22000.1335]
• Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.125
• Edge (web) • edge • web-javascript • Microsoft Edge 108.0.1462.54
[√] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
I'm also running this on Android emulator Pixel 4 API 32.
I am a bit desperate with an error when receiving push notifications in the background, and it is failing due to the error that I indicate below,
I was looking for possible solutions but I haven't found anything that worked, can you help me, maybe it's a bug in the firebase_messaging library? Has anyone experienced something similar?
Devices & versions:
[FAIL] Physical Devide with Android 12: Fail
[✓] Physical Devide with Android 13: run perfect
[✓] Physical Devide with IOs 16.2: run perfect
NOTE: I'm not sure if other versions prior to 12 get this error
Flutter code where the error occurs:
I have tried both possibilities with the same result:
NotificationSettings settings = await FirebaseMessaging.instance.requestPermission();
OR
NotificationSettings settings = await FirebaseMessaging.instance.getNotificationSettings();
Flutter Error:
I/flutter (11341): FlutterFire Messaging: An error occurred in your background messaging handler:
I/flutter (11341): [firebase_messaging/unknown] Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
Flutter environment:
plugins related and installed:
firebase_core: ^2.4.1
firebase_messaging: ^14.2.1
flutter_local_notifications: ^13.0.0
permission_handler: ^10.2.0
fllutter doctor -v
[✓] Flutter (Channel stable, 3.7.0, on macOS 13.1 22C65 darwin-arm64, locale es-ES)
• Flutter version 3.7.0 on channel stable at /Users/josevv/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b06b8b2710 (hace 9 días), 2023-01-23 16:55:55 -0800
• Engine revision b24591ed32
• Dart version 2.19.0
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/josevv/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
[✓] VS Code (version 1.74.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.58.0
[✓] Connected device (3 available)
• NE2213 (mobile) • eea79ab4 • android-arm64 • Android 12 (API 31)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.1 22C65 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Expected behavior: Receive background push notifications
current behavior: on android 12 (haven't been able to check on versions prior to 12), no background push notifications due to mentioned bug
Finally, I have solved it changing for Android (NotificationSettings settings = await FirebaseMessaging.instance.getNotificationSettings(); ) whit this simply piece of code, like this:
if (Platform.isAndroid) {
flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()!
.requestPermission();
} else if (Platform.isIOS) {
NotificationSettings settings = await FirebaseMessaging.instance.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {.....}
}
I'm currently making an app for Android with Flutter, and I'm using google-mobile-ads package to show banner ads.
My environment is VScode & Android emurator by Android Studio.
To run this project Execute this command:
$ flutter run --no-sound-null-safety
Not with Play button.
However if I run with this command, hot reload is disabled. Any edits don't make any changes.
flutter doctor -v;
[√] Flutter (Channel beta, 2.6.0-5.2.pre, on Microsoft Windows [Version 10.0.22000.282], locale ja-JP)
• Flutter version 2.6.0-5.2.pre at D:\src\flutter_windows_2.5.0-stable\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 400608f101 (8 weeks ago), 2021-09-15 15:50:26 -0700
• Engine revision 1d521d89d8
• Dart version 2.15.0 (build 2.15.0-82.2.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at D:\Android
• Platform android-30, build-tools 29.0.3
• Java binary at: D:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.2)
• Android Studio at D:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
[√] VS Code (version 1.62.0)
• VS Code at C:\Users\yukik\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.28.0
[√] Connected device (3 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69
• Edge (web) • edge • web-javascript • Microsoft Edge 95.0.1020.44
• No issues found!
How can I make this possible?
When using flutter run you should be able to hot reload pressing r and to hot restart using R. Just press them in the terminal where you've used flutter run.
If I remember correctly, launching flutter run you should get all these info on the console as a message when starting!
Flutter Doctor -v indicates SDK is there.
(for some reason it says Android Studio is not installed)
**[√] Flutter (Channel stable, 2.2.0, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
• Flutter version 2.2.0 at C:\Users\kaste\Documents\flutter
• Framework revision b22742018b (3 weeks ago), 2021-05-14 19:12:57 -0700
• Engine revision a9d88a4d18
• Dart version 2.13.0
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\kaste\AppData\Local\Android\Sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = C:\Users\kaste\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
• Java version Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
[√] VS Code (version 1.56.2)
• VS Code at C:\Users\kaste\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.22.0
[√] Connected device (3 available)
• sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 90.0.4430.212
• Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.37**
In Android Studio, I get this error message when trying to start a new Flutter App.
Android Studio error message
I can't figure out why it's not working. I can run the default Android Studio flutter app in the Android Virtual Device fine.
?
same thing happened to me when i pointed the path
as
/home/ekele/flutter_sdk/bin
it worked when i changed it to
/home/pompidou/flutter_sdk
change the path below to C:\Users\kaste\Documents\flutter
As said before, you need to set 'flutter installation directory' (you got it as can be shown at your flutter doctor -v command output:
Flutter version 2.2.0 at C:\Users\kaste\Documents\flutter.
Problem is you are setting as flutter SDK your Android SDK installation directory, which is wrong. You need to just set C:\Users\kaste\Documents\flutter instead of C:\Users\kaste\AppData\Local\Android\sdk
As i mentioned in the question,i cannot see anything in the console but Installing build\app\outputs\apk\app.apk... and i just cannot understand the reason because my app is working in the device. I can change the pages but the little informations that i want to see, the prints that i entered in the code are not visible and its very annoying.
Before asking here i have been looking the other questions about this problem but the answers in that questions did not worked for me so i end up asking this in here, i hope you can help me.
here is the console after i click the run button;
Launching lib\main.dart on LG H850 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
an here is the flutter doctor
[√] Flutter (Channel stable, v1.17.0, on Microsoft Windows [Version 10.0.18362.778], locale tr-TR)
• Flutter version 1.17.0 at C:\Users\Mahir Yakup Şahin\flutter
• Framework revision e6b34c2b5c (8 days ago), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\src\Android
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = C:\src\Android
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[√] VS Code (version 1.45.0)
• VS Code at C:\Users\Mahir Yakup Şahin\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.10.1
[√] Connected device (1 available)
• LG H850 • LGH850b31f3def • android-arm64 • Android 8.0.0 (API 26)
• No issues found!
I will be very grateful for any kind of help.
And also i tried in the vscode as well, here is the result,
enter image description here
and sometimes i get an error like this;
enter image description here
Try "flutter clean", that helps in lot many cases..seems like yours is also one of those..
Also..make sure that you have enough storage space on your device (phone or emulator, whatever you re using)..the description on the second image seems like because of the storage issue.