I'm having a strange issue only on one phone right now that I'm able to test only remotely by using TeamViewer and adb.
I'm able to test the device from time to time, but right now I don't know how to fix this issue.
Here is the log:
09-24 10:14:51.553 11416 11465 I flutter : PlatformException(firebase_core, java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.lang.NullPointerException: Attempt to invoke interface method 'long com.google.firebase.auth.a0.M()' on a null object reference, null)
09-24 10:14:51.553 11416 11465 E flutter : [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(firebase_core, java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.lang.NullPointerException: Attempt to invoke interface method 'long com.google.firebase.auth.a0.M()' on a null object reference, null)
09-24 10:14:51.553 11416 11465 E flutter : #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:572)
09-24 10:14:51.553 11416 11465 E flutter : #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:161)
09-24 10:14:51.553 11416 11465 E flutter : <asynchronous suspension>
09-24 10:14:51.553 11416 11465 E flutter : #2 MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:347)
09-24 10:14:51.553 11416 11465 E flutter : <asynchronous suspension>
09-24 10:14:51.553 11416 11465 E flutter : #3 MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30)
09-24 10:14:51.553 11416 11465 E flutter : <asynchronous suspension>
09-24 10:14:51.553 11416 11465 E flutter : #4 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:75)
09-24 10:14:51.553 11416 11465 E flutter : <asynchronous suspension>
09-24 10:14:51.553 11416 11465 E flutter : #5 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43)
09-24 10:14:51.553 11416 11465 E flutter : <asynchronous suspension>
09-24 10:14:51.553 11416 11465 E flutter : #6 main (package:training/main.dart:15)
09-24 10:14:51.553 11416 11465 E flutter : <asynchronous suspension>
09-24 10:14:51.553 11416 11465 E flutter
Here is my main.dart file:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
try {
await Firebase.initializeApp(); // error is happening right here
unawaited(_initializeCrashlytics());
await initInjections();
final bool injectAnalytics = isReleaseVersion();
runZonedGuarded(() {
runApp(TrainingApp(injectAnalytics: injectAnalytics));
}, (error, stackTrace) {
print(error);
FirebaseCrashlytics.instance.recordError(error, stackTrace);
});
} catch (e) {
print(e);
rethrow;
}
}
Future<void> _initializeCrashlytics() async {
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(isReleaseVersion());
final Function originalOnError = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails errorDetails) async {
print(errorDetails);
await FirebaseCrashlytics.instance.recordFlutterError(errorDetails);
// Forward to original handler.
originalOnError(errorDetails);
};
}
All other phones (Android/iOS) do not have such problem. Only one right now. But because this problem is connected with Firebase initialization - I'm not able to post this crashes to Crashlytics to have the full set of problem devices.
Run flutter doctor and paste the output below:
Click To Expand
flutter doctor -v
[✓] Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale en-RU)
• Flutter version 1.20.4 at /Users/mig35/Documents/tools/flutter
• Framework revision fba99f6cf9 (9 days ago), 2020-09-14 15:32:52 -0700
• Engine revision d1bc06f032
• Dart version 2.9.2
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/mig35/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = /Users/mig35/Library/Android/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-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.0, Build version 12A7209
• CocoaPods version 1.9.3
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 49.0.2
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.36.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.2.0
[!] Connected device
! No devices available
! Doctor found issues in 1 category.
Run flutter pub deps -- --style=compact and paste the output below:
Click To Expand
flutter pub deps -- --style=compact
Dart SDK 2.9.2
Flutter SDK 1.20.4
training 2.1.2+103
dependencies:
- admob_flutter 1.0.0 [flutter meta]
- apple_sign_in 0.1.0 [flutter]
- audioplayers 0.16.1 [uuid path_provider flutter flutter_web_plugins]
- auto_size_text 2.1.0 [flutter]
- built_value 7.1.0 [built_collection collection fixnum quiver]
- color 2.1.1
- cupertino_icons 1.0.0
- custom_audio_focus 0.0.1 [flutter]
- decimal 0.3.5 [rational]
- firebase_admob 0.10.0-dev.1 [meta platform flutter firebase_core]
- firebase_analytics 6.0.0 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface]
- firebase_auth 0.18.0+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]
- firebase_core 0.5.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_crashlytics 0.2.0 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface]
- firebase_database 4.0.0 [flutter firebase_core]
- firebase_dynamic_links 0.6.0 [flutter firebase_core]
- firebase_remote_config 0.4.0 [flutter firebase_core]
- 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_material_color_picker 1.0.5 [flutter]
- flutter_rating_bar 3.0.1+1 [flutter]
- flutter_redux 0.6.0 [meta redux flutter]
- flutter_rounded_date_picker 0.3.0 [flutter]
- flutter_signin_button 1.1.0 [flutter font_awesome_flutter]
- flutter_simple_dependency_injection 1.0.3
- flutter_svg 0.19.0 [path_drawing xml vector_math meta flutter]
- fluttertoast 7.1.1 [flutter flutter_web_plugins]
- google_sign_in 4.5.4 [google_sign_in_platform_interface flutter meta google_sign_in_web]
- in_app_update 1.1.11 [flutter]
- json_serializable 3.5.0 [analyzer build build_config json_annotation meta path source_gen]
- kt_dart 0.7.0+1
- launch_review 2.0.0 [flutter]
- package_info 0.4.3 [flutter]
- pedantic 1.9.0
- reorderables 0.2.12 [flutter]
- rxdart 0.22.6
- screen 0.0.5 [flutter]
- selectable_autolink_text 1.3.4 [flutter]
- share 0.6.5 [meta mime flutter]
- shared_preferences 0.5.12 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- stream_transform 1.2.0
- touch_indicator 1.0.3 [flutter]
- tuple 1.0.3 [quiver]
- url_launcher 5.7.1 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]
- uuid 2.2.2 [crypto convert]
dev dependencies:
- build_runner 1.10.1 [analyzer args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- built_value_generator 7.1.0 [analyzer build build_config built_collection built_value source_gen quiver]
- 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]
- intl_translation 0.17.10+1 [analyzer args dart_style intl path petitparser]
dependency overrides:
- flutter_rounded_date_picker 0.3.0 [flutter]
- reorderables 0.2.12 [flutter]
transitive dependencies:
- _fe_analyzer_shared 6.0.0 [meta]
- analyzer 0.39.14 [_fe_analyzer_shared args charcode cli_util collection convert crypto glob html meta package_config path pub_semver source_span watcher yaml]
- args 1.6.0
- async 2.4.2 [collection]
- boolean_selector 2.0.0 [source_span string_scanner]
- build 1.3.0 [analyzer async convert crypto logging meta path glob]
- build_config 0.4.2 [checked_yaml json_annotation meta path pubspec_parse yaml]
- build_daemon 2.1.4 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 1.3.11 [analyzer build crypto graphs logging path package_config pub_semver]
- build_runner_core 6.0.1 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml]
- built_collection 4.3.2 [collection quiver]
- characters 1.0.0
- charcode 1.1.3
- checked_yaml 1.0.2 [json_annotation source_span yaml]
- cli_util 0.1.4 [path]
- clock 1.0.1 [meta]
- code_builder 3.4.1 [built_collection built_value collection matcher meta]
- collection 1.14.13
- convert 2.1.1 [charcode typed_data]
- crypto 2.1.5 [collection convert typed_data]
- csslib 0.16.2 [source_span]
- dart_style 1.3.6 [analyzer args path source_span]
- fake_async 1.1.0 [clock collection]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- firebase 7.3.0 [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.0.1 [flutter meta firebase_core plugin_platform_interface]
- firebase_auth_web 0.3.0+1 [flutter flutter_web_plugins firebase meta http_parser intl firebase_core firebase_auth_platform_interface js]
- firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_crashlytics_platform_interface 1.0.0 [flutter meta collection firebase_core plugin_platform_interface]
- fixnum 0.10.11
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- font_awesome_flutter 8.8.1 [flutter]
- glob 1.2.0 [async collection node_io path pedantic string_scanner]
- google_sign_in_platform_interface 1.1.2 [flutter meta quiver]
- google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
- graphs 0.2.0
- html 0.14.0+3 [csslib source_span]
- http 0.12.2 [http_parser path pedantic]
- http_multi_server 2.2.0 [async]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- intl 0.16.1 [path]
- io 0.3.4 [charcode meta path string_scanner]
- js 0.6.2
- json_annotation 3.1.0
- logging 0.11.4
- matcher 0.12.8 [stack_trace]
- meta 1.1.8
- mime 0.9.7
- node_interop 1.1.1 [js]
- node_io 1.1.1 [node_interop path]
- package_config 1.9.3 [path charcode]
- path 1.7.0
- path_drawing 0.4.1+1 [vector_math meta path_parsing flutter]
- path_parsing 0.1.4 [vector_math meta]
- path_provider 1.6.18 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+4 [flutter]
- path_provider_platform_interface 1.0.3 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+1 [path_provider_platform_interface meta path flutter ffi win32]
- petitparser 3.0.4 [meta]
- platform 2.2.1
- plugin_platform_interface 1.0.2 [meta]
- pool 1.4.0 [async stack_trace]
- process 3.0.13 [file intl meta path platform]
- pub_semver 1.4.4 [collection]
- pubspec_parse 0.1.5 [checked_yaml json_annotation pub_semver yaml]
- quiver 2.1.3 [matcher meta]
- rational 0.3.8
- redux 4.0.0+3
- shared_preferences_linux 0.0.2+2 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 0.0.1+10 [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+1 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows]
- shelf 0.7.9 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel]
- sky_engine 0.0.99
- source_gen 0.9.7+1 [analyzer async build dart_style glob meta path pedantic source_span]
- source_span 1.7.0 [charcode collection meta path term_glyph]
- stack_trace 1.9.5 [path]
- stream_channel 2.0.0 [async]
- string_scanner 1.0.5 [charcode meta source_span]
- term_glyph 1.1.0
- test_api 0.2.17 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timing 0.1.1+2 [json_annotation]
- typed_data 1.2.0 [collection]
- url_launcher_linux 0.0.1+1 [flutter]
- url_launcher_macos 0.0.1+8 [flutter]
- url_launcher_platform_interface 1.0.8 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.4+1 [url_launcher_platform_interface flutter flutter_web_plugins meta]
- url_launcher_windows 0.0.1+1 [flutter]
- vector_math 2.0.8
- watcher 0.9.7+15 [async path pedantic]
- web_socket_channel 1.1.0 [async crypto stream_channel]
- win32 1.7.3 [ffi]
- xdg_directories 0.1.0 [path process flutter]
- xml 4.5.1 [collection convert meta petitparser]
- yaml 2.2.1 [charcode collection string_scanner source_span]
Which device doesn't it work on?
The device with the problem is Samsung A5 (2017) with Android 8.0.
Other devices that I can test and everything works fine (exact the same build): Samsung S9, Xiaomi Mi4C, Xiaomi Mi5C.
@mig35,
Although I don't have the same device, but a closer one I got is Samsung A2 with 8.1.0 and am able to launch app without any issues. I tried below code sample:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
debugPrint('main');
FirebaseAuth.instance.authStateChanges().listen((event) {
debugPrint('event ${event.toString()}');
});
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('test'),
),
),
));
}
Can you try above code sample and see if it helps ?
Thanks
hey @darshankawar ,
I've used exact the same code except I changed debugPrint to print to be able to see logs in release builds (I'm compiling in the release and push update through the Internal Testers group in Google Play).
The problem is still there and still exact the same.
hey @darshankawar @Ehesp ,
any update here? anything that I can do to prevent app crash?
I'm afraid that this is not just one device issue, because I'm not able to find this issue remotely (because crashlytics is not working). also because I'm using DB from firebase I have to have firebase in my app, so I'm not able just to try/catch and disable all the firebase stuff.
do you guys have anything to help me?
hey here,
I was able to fix this issue by clearing application data... so for now my workaround is:
(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).clearApplicationUserData()
The bad thing is that this method caused application kill, but the good thing that the second launch is ok now.
And also that means that I'm not able to reproduce this anymore...
I am having the same issue. Some users are reporting that the app is not working anymore. I cannot reproduce the issue myself. The screenshot they are sharing includes the same stack trace.
@mig35 Can you explain better how you implemented the workaround? Thank you!
hey @mgonzalezc
I've created custom Platform channel and added try catch for the await Firebase.initializeApp();.
And as soon as I catch an exception I'm calling my Platform channel that execute this code (context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).clearApplicationUserData().
After that code, application dies and has no user settings at all (like a fresh install). And user has to open application one more time and enter his login information again.
I do not like this solution and would like to find exact file that cause this problem, but I can not reproduce this issue so I've fixed it with the only solution that I know right now.
Thank you @mig35 for sharing
Yes, I understand. It is also being challenging for our team because none of us can reproduce the issue. In addition, as far as Crashlytics is not initializing, we cannot see any reports there. Did you try to reinstall the app before implementing your solution?
@mgonzalezc that solution totally works because I had a chance to fix this issue by clearing user's data at the only one phone that I was able to test remotely with this issue.
I haven't tried to do reinstall and because the issue is gone now on the test device I'm not able to test it now.
@mig35 Ok, thank you
If it helps someone else, this is how we solved it:
We added this line
android:allowBackup="false"
under application in the AndroidManifest.
Then, we asked our users with issues to reinstall and it worked for them.
And how have you asked them @mgonzalezc ?
The key problem as for me is that this is an entry point of the application and the only thing we can do is to create a platform channel with an alert (or any other message UI) in the native code and ask them to relaunch (in my solution) or to reinstall (in yours). Otherwise we are not able to target all people that will have this issue - not everyone will write to the support or reinstall, usually users just remove the application especially if it is a new one for them.
You are completely right @mig35 . We asked to those who wrote to support but of course, it is possible that this happens to someone that didn't. For these cases, we ended up adding your solution with a button inside a screen that informs the user that their data needs to be restarted. I.e, we surrounded Firebase.initializeApp in a try/catch and if there is an error, then we show the screen. At this moment, we have not found any other workaround.
We are also getting many reports from Android users about this issue. Is there any other work around for it instead of clearing app data?
Most helpful comment
You are completely right @mig35 . We asked to those who wrote to support but of course, it is possible that this happens to someone that didn't. For these cases, we ended up adding your solution with a button inside a screen that informs the user that their data needs to be restarted. I.e, we surrounded Firebase.initializeApp in a try/catch and if there is an error, then we show the screen. At this moment, we have not found any other workaround.