firebase / flutterfire

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

Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) in "IOS" only #6263

Closed SyedMuhammadMuhid closed 3 years ago

SyedMuhammadMuhid commented 3 years ago

I am unable to resolve this error that I get while I run my flutter app on ios Simulator (IPhone 12 pro max). This application is running normally on android emulators and devices.

The message that I get in Run:

---------------------------------------------------------------------------------------------------
Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...
Xcode build done. 643.6s
Debug service listening on ws://127.0.0.1:59848/2DbBjErz6yw=/ws
Syncing files to device iPhone 12 Pro Max...

[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)

#1 MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:344:35)

#2 MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30:23)

#3 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:77:7)

#4 Firebase.initializeApp (package:firebase_core/src/firebase.dart:41:31)

#5 main (package:farmex/main.dart:19:3)

This is my main.dart



import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'Screens/select_language.dart';
import 'Services/phone_stream_service.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'constants/language/language_preferences.dart';
import 'constants/constants_global.dart';
import 'package:localstorage/localstorage.dart';
import 'package:farmex/Services/api_services.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main()async {

WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

runApp(MyApp());
await getLanguage();
}

class MyApp extends StatefulWidget {

@override
_MyAppState createState() => _MyAppState();
static _MyAppState of(BuildContext context) => context.findAncestorStateOfType<_MyAppState>();
}

class _MyAppState extends State with WidgetsBindingObserver{

Locale _locale;
bool wait = true;
User firebaseuser;

void setLocale(Locale value) {
if (mounted) {
setState(() {
_locale = value;
});
}
}

@override
void initState() {

super.initState();

WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

@override
Widget build(BuildContext context) {

if(langChanger==true){
  getBioData();
}

 return wait ? Container(
  color: Colors.white,
) : MaterialApp(

  locale:  Locale( (userLanguage != null && BioData != null) ? (userLanguage == BioData.userProfileLanguage ? userLanguage : BioData.userProfileLanguage) : (userLanguage == null && BioData != null)?(BioData.userProfileLanguage):(userLanguage != null && BioData == null ? userLanguage: "en" )),
  debugShowCheckedModeBanner: false,

  title:'Flutter Demo',
  theme: ThemeData(
    primarySwatch: Colors.green,
    fontFamily: 'geomanist',
    visualDensity: VisualDensity.adaptivePlatformDensity,
  ),

  home: PhoneAuthService().handleAuth(),

  localizationsDelegates: [
    AppLocalizations.delegate, // Add this line
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],

  supportedLocales: [
    const Locale('ur', ''), // Urdu, no country code
    const Locale('en', ''), // English, no country code
  ],
);
}

void getBioData()async {
langChanger=false;
firebaseuser = await FirebaseAuth.instance.currentUser;
if(firebaseuser!=null) {
Global_access_token = await LoginServices(
firebaseId: firebaseuser.uid.toString(), appId: Global_appId)
.getAccessToken();
print(Global_access_token);
await GetUserBioData(accessToken: Global_access_token)
.GetUserBioDataDetails()
.then((value) {
if (mounted) {
setState(() {
BioData = value[0];
wait = false;
});
}
print(
"I am the BioData var, i contain language data. Language is: ${BioData
.userProfileLanguage}");
});
}
else{
if (mounted) {
setState(() {
wait = false;
});
}
}
}
}

void getLanguage()async{

SharedPreferences.setMockInitialValues({});
SharedPreferences Lang = await SharedPreferences.getInstance();
userLanguage = Lang.getString('userLanguage');
print('getLanguage() called, userlanguage : ${userLanguage}');
}

This is my project's pubspec.yaml


name: farmex
description: A new Flutter application.

version: 1.0.1+8

environment:
sdk: ">=2.7.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter

cupertino_icons: ^1.0.3
google_fonts: ^2.1.0

pin_entry_text_field: ^0.1.4
font_awesome_flutter: ^9.0.0
flutter_svg: ^0.22.0
table_calendar: ^3.0.0
roundcheckbox: ^2.0.1
http: ^0.13.3
flutter_spinkit: ^5.0.0
toast: ^0.1.5
modal_progress_hud: ^0.1.3

intl: ^0.17.0
im_stepper: ^0.1.3
google_maps_flutter: ^2.0.5
flutter_datetime_picker: ^1.5.1
geolocator: ^7.0.3
location: ^4.1.1
geocoding: ^2.0.0
geocoder: ^0.2.1
image_picker: ^0.7.5+3
firebase_storage: ^8.1.0
flutter_tts: ^3.1.0
charts_flutter: ^0.10.0
photo_view: ^0.11.1
showcaseview: ^1.0.0
holding_gesture: ^1.1.0
flutter_plugin_record: ^1.0.1
audioplayers: ^0.19.0
permission_handler: ^8.0.0+2
shared_preferences: ^2.0.6
dots_indicator: ^2.0.0
localstorage: ^4.0.0+1
qr_code_scanner: ^0.4.0
android_intent: ^2.0.1
firebase_auth: ^1.2.0
firebase_core: "^1.2.0"

dependency_overrides:

uses-material-design: true

assets:
- assets/images/
- assets/icons/
- assets/weather/
- assets/more/
- assets/news/

fonts:
- family: geomanist
fonts:
- asset: fonts/geomanist-regular-webfont.ttf
---------------------------------------------------------------------------------------------------

This is the project's AppDelegate.swift
---------------------------------------------------------------------------------------------------

import UIKit
import Firebase
import Flutter
import GoogleMaps

@UIApplicationMain

@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
) -> Bool {
FirebaseApp.configure()
GMSServices.provideAPIKey("AIzaSyBvwaQSH5IxqTPWIHA2LctbqdrP8MRyK_w")
return super.application(application, didFinishLaunchingWithOptions: launchOptions) // YES;
}
}
---------------------------------------------------------------------------------------------------

This is the project's AppDelegate.m
---------------------------------------------------------------------------------------------------

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"

@import UIKit;
@import Firebase;

@implementation AppDelegate

(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GMSServices provideAPIKey:@"AIzaSyBvwaQSH5IxqTPWIHA2LctbqdrP8MRyK_w"];
[FIRApp configure];
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application didFinishLaunchingWithOptions:launchOptions]; // YES;
}
@EnD
---------------------------------------------------------------------------------------------------

This is the Podfile
---------------------------------------------------------------------------------------------------

platform :ios, '10.2'

ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), FILE)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do

pod 'Firebase/Auth'
pod 'Firebase/Firestore'
pod 'Firebase/Core'

use_frameworks! #add here
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(FILE))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.2'

          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
            '$(inherited)',

            'PERMISSION_CAMERA=1',
            'PERMISSION_MICROPHONE=1',
            'PERMISSION_PHOTOS=1',
            'PERMISSION_LOCATION=1',
            'PERMISSION_MEDIA_LIBRARY=1',
            'PERMISSION_SENSORS=1',

          ]

  end
end
end

---------------------------------------------------------------------------------------------------

flutter doctor -v
---------------------------------------------------------------------------------------------------

flutter doctor -v
[βœ“] Flutter (Channel stable, 2.2.0, on macOS 11.3 20E232 darwin-x64, locale en-AE)
β€’ Flutter version 2.2.0 at /Users/xyphertechnologies/developer/flutter
β€’ Framework revision b22742018b (13 days 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 /Users/xyphertechnologies/Library/Android/sdk
β€’ Platform android-30, build-tools 30.0.3
β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[βœ“] Xcode - develop for iOS and macOS
β€’ Xcode at /Applications/Xcode.app/Contents/Developer
β€’ Xcode 12.5, Build version 12E262
β€’ CocoaPods version 1.10.1

[βœ“] Chrome - develop for the web
β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[βœ“] Android Studio (version 4.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 1.8.0_242-release-1644-b3-6915495)

[βœ“] Connected device (2 available)
β€’ iPhone 12 Pro Max (mobile) β€’ C0615887-44CC-4010-8DF8-7F77ED55F4D4 β€’ ios β€’ com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)

---------------------------------------------------------------------------------------------------

Android studio ios file structure:
<img width="462" alt="Screen Shot 2021-05-28 at 4 25 09 PM" src="https://user-images.githubusercontent.com/72338712/119980280-82e64380-bfd5-11eb-9be8-0270fabb5c2b.png">

xcode Runner.xcworkspace file structure:
<img width="462" alt="Screen Shot 2021-05-28 at 4 25 53 PM" src="https://user-images.githubusercontent.com/72338712/119981548-36036c80-bfd7-11eb-9669-92d86d954e65.png">

I hope you can help me find a solution to this issue, I am stuck on this for days now, thanks.

darshankawar commented 3 years ago

@SyedMuhammadMuhid

You may try few things as below:

  1. Run flutter clean or flutter pub cache repair and then flutter run to see if it helps.

  2. Can you remove shared preferences plugin from pubspec.yaml and try again to see if you get same error still ?

  3. Also, try to remove other 3rd party plugins listed below:

`import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:localstorage/localstorage.dart'; import 'package:farmex/Services/api_services.dart';`

and see if it helps.

google-oss-bot commented 3 years ago

Hey @SyedMuhammadMuhid. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 3 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@SyedMuhammadMuhid if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.