[firebase_core] Firebase initialization fails in release mode when minifyEnabled=true (PlatformException: FirebaseCoreHostApi.initializeCore)
Is there an existing issue for this?
- [x] I have searched the existing issues.
Which plugins are affected?
Analytics, Cloud Functions, Crashlytics, Remote Config, Storage
Which platforms are affected?
Android
Description
Description
Firebase initialization fails on Android release builds when minifyEnabled is set to true. The same project runs fine in debug mode or when minifyEnabled is false.
Observed behavior PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeCore", null, null)
Expected behavior
Firebase should initialize successfully in release builds while code shrinking (minifyEnabled=true) is enabled.
Build Configuration android/app/build.gradle buildTypes { debug { signingConfig = signingConfigs.debug } release { minifyEnabled true shrinkResources false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' signingConfig = signingConfigs.release } }
Relevant ProGuard Rules -keepattributes Signature,InnerClasses,EnclosingMethod,Annotation
-keep class com.google.firebase.** { ; } -keep class com.google.android.gms.* { ; } -keepclassmembers class com.google.firebase.* { ; } -keepclassmembers class com.google.android.gms.* { *; }
-keep class io.flutter.app.** { ; } -keep class io.flutter.plugin.* { ; } -keep class io.flutter.util.* { ; } -keep class io.flutter.view.* { ; } -keep class io.flutter.* { ; } -keep class io.flutter.plugins.* { *; }
-keep class dev.flutter.pigeon.** { ; } -keepclassmembers class dev.flutter.pigeon.* { *; }
Reproducing the issue
Reproducing the issue
Create a new Flutter project with Firebase integration (Firebase Core initialized in main.dart).
Enable code shrinking in build.gradle:
minifyEnabled true
Build the release APK:
flutter build apk --release
Install and run on a device.
Observe crash on startup with PlatformException(channel-error, Unable to establish connection...).
Change minifyEnabled to false and rebuild β app works normally.
Firebase Core version
^4.2.0
Flutter Version
3.35.6
Relevant Log Output
PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeCore"., null, null)
I/flutter (21968): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
I/flutter (21968): β #0 FirebaseCoreHostApi.initializeCore (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:301)
I/flutter (21968): β #1 <asynchronous suspension>
I/flutter (21968): β #2 MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:29)
I/flutter (21968): β #3 <asynchronous suspension>
I/flutter (21968): β #4 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:70)
I/flutter (21968): β #5 <asynchronous suspension>
I/flutter (21968): β #6 Firebase.initializeApp (package:firebase_core/src/firebase.dart:78)
I/flutter (21968): β #7 <asynchronous suspension>
I/flutter (21968): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
I/flutter (21968): β β Error during critical initialization
I/flutter (21968): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
I/flutter (21968): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
I/flutter (21968): β Bad state: GetIt: Object/factory with type FirebaseAnalyticsObserver is not registered inside GetIt.
I/flutter (21968): β (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
I/flutter (21968): β Did you forget to register it?)
I/flutter (21968): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
I/flutter (21968): β #0 throwIfNot (package:get_it/get_it_impl.dart:14)
I/flutter (21968): β #1 _GetItImplementation._findRegistrationByNameAndType (package:get_it/get_it_impl.dart:583)
I/flutter (21968): β #2 _GetItImplementation._get (package:get_it/get_it_impl.dart:641)
I/flutter (21968): β #3 _GetItImplementation.get (package:get_it/get_it_impl.dart:608)
I/flutter (21968): β #4 _GetItImplementation.call (package:get_it/get_it_impl.dart:720)
I/flutter (21968): β #5 main.<anonymous closure> (package:online_tribes/main.dart:99)
I/flutter (21968): β #6 <asynchronous suspension>
I/flutter (21968): β #7 main (package:online_tribes/main.dart:80)
I/flutter (21968): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
I/flutter (21968): β β Unhandled error caught in runZonedGuarded
Flutter dependencies
Expand Flutter dependencies snippet
Dart SDK 3.9.2
Flutter SDK 3.35.6
online_tribes 4.0.0+213
dependencies:
- android_intent_plus 5.3.1 [flutter platform meta]
- app_links 6.4.1 [flutter app_links_linux app_links_platform_interface app_links_web]
- app_tracking_transparency 2.0.6+1 [flutter]
- appsflyer_sdk 6.17.3 [flutter json_annotation]
- bloc 9.0.0 [meta]
- cached_network_image 3.4.1 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image]
- cloud_firestore 6.0.3 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cloud_functions 6.0.3 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter]
- collection 1.19.1
- connectivity_plus 6.1.5 [flutter flutter_web_plugins connectivity_plus_platform_interface web meta nm collection]
- csv 6.0.0
- dartz 0.10.1
- device_info_plus 10.1.2 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta web win32 win32_registry]
- dio 5.9.0 [async collection http_parser meta mime path dio_web_adapter]
- dotted_border 2.1.0 [flutter path_drawing]
- emoji_picker_flutter 3.1.0 [flutter flutter_web_plugins plugin_platform_interface shared_preferences web]
- equatable 2.0.7 [collection meta]
- extended_image 10.0.1 [extended_image_library flutter meta vector_math]
- facebook_app_events 0.20.1 [flutter]
- feedback 3.2.0 [flutter flutter_localizations]
- ffmpeg_kit_flutter_new 3.2.0 [ffmpeg_kit_flutter_platform_interface flutter]
- firebase_analytics 12.0.3 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_app_installations 0.4.0+3 [firebase_app_installations_platform_interface firebase_app_installations_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 6.1.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 4.2.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 5.0.3 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_messaging 16.0.3 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_remote_config 6.1.0 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter]
- firebase_storage 13.0.3 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- fl_chart 0.69.2 [equatable flutter]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_bloc 9.1.1 [bloc flutter provider]
- flutter_cache_manager 3.4.1 [clock collection file flutter http path path_provider rxdart sqflite uuid]
- flutter_chat_types 3.6.2 [equatable json_annotation meta]
- flutter_chat_ui 1.6.15 [diffutil_dart equatable flutter flutter_chat_types flutter_link_previewer flutter_parsed_text intl meta photo_view scroll_to_index url_launcher visibility_detector]
- flutter_dotenv 5.2.1 [flutter]
- flutter_html 3.0.0 [html csslib collection list_counter flutter]
- flutter_image_compress 2.4.0 [flutter flutter_image_compress_platform_interface flutter_image_compress_common flutter_image_compress_web flutter_image_compress_macos flutter_image_compress_ohos]
- flutter_inappwebview 6.1.5 [flutter flutter_inappwebview_platform_interface flutter_inappwebview_android flutter_inappwebview_ios flutter_inappwebview_macos flutter_inappwebview_web flutter_inappwebview_windows]
- flutter_keyboard_visibility 6.0.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_linux flutter_keyboard_visibility_macos flutter_keyboard_visibility_web flutter_keyboard_visibility_windows flutter]
- flutter_local_notifications 19.4.1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_windows flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl path]
- flutter_markdown 0.7.7+1 [flutter markdown meta path]
- flutter_native_splash 2.4.6 [args flutter flutter_web_plugins html image meta path universal_io xml yaml ansicolor]
- flutter_screenutil 5.9.3 [flutter]
- flutter_secure_storage 9.2.4 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta]
- flutter_slidable 3.1.2 [flutter]
- flutter_svg 2.2.0 [flutter http vector_graphics vector_graphics_codec vector_graphics_compiler]
- flutter_switch 0.3.2 [flutter]
- freezed_annotation 2.4.4 [collection json_annotation meta]
- get_it 8.2.0 [async collection meta]
- get_thumbnail_video 0.7.3 [flutter flutter_web_plugins web plugin_platform_interface cross_file]
- giphy_get 3.6.1 [flutter flutter_localizations provider extended_image flutter_staggered_grid_view meta http url_launcher]
- go_router 15.1.3 [collection flutter flutter_web_plugins logging meta]
- google_sign_in 7.2.0 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- google_sign_in_mocks 0.4.1 [flutter google_sign_in]
- googleapis 13.2.0 [_discoveryapis_commons http]
- googleapis_auth 2.0.0 [args crypto google_identity_services_web http http_parser]
- hive_ce 2.11.3 [meta crypto web isolate_channel json_annotation]
- hive_ce_flutter 2.3.2 [flutter hive_ce path_provider path]
- http 1.5.0 [async http_parser meta web]
- hugeicons 0.0.11 [flutter]
- icons_plus 5.0.0 [flutter flutter_svg]
- image_picker 1.2.0 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows]
- infinite_scroll_pagination 5.1.1 [flutter flutter_staggered_grid_view sliver_tools collection meta]
- injectable 2.5.1 [get_it meta]
- internet_connection_checker 3.0.1 [connectivity_plus equatable flutter http]
- intl 0.19.0 [clock meta path]
- introduction_screen 3.1.17 [flutter collection dots_indicator flutter_keyboard_visibility]
- json_annotation 4.9.0 [meta]
- l10n_flutter 1.0.7 [flutter flutter_localizations build cupertino_icons]
- language_detector 1.0.1 [flutter translator]
- linkfy_text 1.1.6 [platform flutter]
- loading_indicator 3.1.1 [flutter async collection]
- logger 2.6.1 [meta]
- meta 1.16.0
- mime 2.0.0
- no_screenshot 0.3.1 [flutter plugin_platform_interface]
- ntp 2.0.0
- package_info_plus 8.3.1 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface web win32 clock]
- path 1.9.1
- path_provider 2.1.5 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- percent_indicator 4.2.5 [flutter]
- permission_handler 12.0.1 [flutter meta permission_handler_android permission_handler_apple permission_handler_html permission_handler_windows permission_handler_platform_interface]
- purchases_flutter 8.10.6 [flutter freezed_annotation json_annotation]
- purchases_ui_flutter 8.10.6 [purchases_flutter flutter plugin_platform_interface]
- qr_flutter 4.1.0 [flutter qr]
- rive 0.13.20 [collection flutter flutter_web_plugins http meta plugin_platform_interface rive_common]
- rxdart 0.28.0
- shake_gesture 1.2.0 [flutter shake_gesture_android shake_gesture_ios shake_gesture_platform_interface]
- share_plus 12.0.0 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi web win32]
- shared_preferences 2.5.3 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shimmer 3.0.0 [flutter]
- sign_in_button 3.2.0 [flutter font_awesome_flutter]
- sign_in_with_apple 7.0.1 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web]
- store_redirect 2.0.4 [flutter]
- url_launcher 6.3.2 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- uuid 4.5.1 [crypto sprintf meta fixnum]
- video_compress 3.1.4 [flutter]
- video_player 2.10.0 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web]
- video_trimmer 5.0.0 [flutter video_player get_thumbnail_video flutter_native_video_trimmer path_provider intl path transparent_image image]
- visibility_detector 0.4.0+2 [flutter]
- wechat_assets_picker 9.8.0 [flutter wechat_picker_library extended_image photo_manager photo_manager_image_provider provider video_player visibility_detector]
- wechat_camera_picker 4.4.0 [flutter wechat_picker_library camera camera_android camera_platform_interface collection path photo_manager photo_manager_image_provider sensors_plus video_player]
dev dependencies:
- build_runner 2.5.4 [...]
- flutter_gen_runner 5.11.0 [...]
- flutter_lints 4.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing collection meta stream_channel]
- freezed 2.5.8 [...]
- go_router_builder 2.9.0 [...]
- hive_ce_generator 1.9.2 [...]
- injectable_generator 2.7.0 [...]
- integration_test 0.0.0 [flutter flutter_driver flutter_test path vm_service]
- json_serializable 6.9.5 [...]
- mockito 5.4.6 [...]
dependency overrides:
- intl 0.19.0 [clock meta path]
</details>
### Additional context and comments
_No response_
Hi @budda24, I'm unable to reproduce this issue with the firebase_core example app, after setting minifyEnabled to true. Could you clear your pub cache(flutter pub cache clean) and try again. Also worth testing against the firebase_core example app on your end.
facing the same issue
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeCore"., null, null)
Issue is also occuring when minifyEnabled = false
facing the same issue
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeCore"., null, null)
Issue is also occuring when minifyEnabled = false
Setting minifyEnabled to false fixed the issue for me. Now Iβm comparing my setup with the official Firebase example since that one runs fine. Iβm trying to spot whatβs different between the example and my own repository β maybe something in proguard-rules.pro is creating an issue
@budda24, I believe so. Could you try without the proguard rules and observe the outcome?
HiΒ @budda24 Β I noticed you are usingΒ ffmpeg_kit_flutter_new 3.2.0Β dependencies so you need to add ProGuard rules for that and after these changes, my issue is fixed
In my proguard file, i have added thisΒ -keep class com.antonkarpenko.ffmpegkit.** { *; }Β bcz in latestΒ ffmpeg_kit_flutter_new 3.2.0Β package example also provided so
Before
#ffmpeg_kit
-keep class com.arthenica.ffmpegkit.** { *; }
-keep class org.ffmpeg.** { *; }
-dontwarn com.arthenica.ffmpegkit.**
-dontwarn org.ffmpeg.**
After
#ffmpeg_kit
-keep class com.arthenica.ffmpegkit.** { *; }
-keep class org.ffmpeg.** { *; }
-dontwarn com.arthenica.ffmpegkit.**
-dontwarn org.ffmpeg.**
-keep class com.antonkarpenko.ffmpegkit.** { *; }
References β¨ firebase/flutterfire/issues/17533 ffmpeg_kit_flutter/issues/76
Hello all, @hrithikM31 did you find solution ? Facing same issue from my side @budda24 can you provide your proguard-rules.pro ?
Just with minifyEnabled = false, issue is also occuring
This issue was triggered by upgrading to 3.35.7 (and Firebase 4.0.2)
@husen313 solution fixed my issue.
@budda24 , don't have the ffmpeg_kit ...
I have tried with new repo (with new .gradle.kts), and same problem. There is a serious problem with the config ... I'm stuck on it for 3 days, nothing works.
I was facing the same issue out of a sudden on an older project, I assumed it's because I upgraded flutter version but packages were still outdated. I tried clearing the cache, upgrading the packages, cleaning up the project and rebuilding it. but nothing worked, until I saw @husen313 comment on FFMPEG pro-guard rules.
I added the required rules in the pro-guard file and boom everything got solved.
In all the other situations, there could be another package which could be causing issues for you or some pro-guard rules messing it all up.
I suggest check all the packages and related pro-guard rules for them, this might solve it for you (if any.. FFMPEG didn't have any pro-guard rules listed in it's pub.dev page too).
Hi @budda24, thanks for confirming this issue was resolved for you. I'll close this now.
@SelaseKay , I have created a fresh new Flutter project, and get the same issue with. Flutter 3.35.7 (and firebase_core 4.2.1).
There is a serious problem of compatibility on Release.
Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeCore"., null, null)
Upgrade to firebase_core_platform_interface 6.0.2 β this version includes a fix for the bug related to the demoProjectId argument in Firebase.initializeApp(). The fix was shipped in commit 09d03aac under the change: βFIX: a bug with the demoProjectId arg to Firebase.initializeApp() (#17703)β