AngeloAvv / flutter_flavorizr

A flutter utility to easily create flavors in your flutter application
https://pub.dev/packages/flutter_flavorizr
MIT License
465 stars 84 forks source link

Firebase configuration #174

Open jempis opened 1 year ago

jempis commented 1 year ago

Hi all, i have try to implement the flutter_flavorizr with 2 flavors e two relative firebase projects. This is the configuration in pubspec.yaml

flavorizr:
  app:
    android:
      flavorDimensions: "flavor-type"
    ios:
  flavors:
    development:
      app:
        name: "Toov Dev"

      android:
        applicationId: "com.example.toov.app.dev"
        firebase:
          config: "config/development/google-services.json"

      ios:
        bundleId: "com.example.toov.app.dev"
        firebase:
          config: "config/development/GoogleService-Info.plist"

    production:
      app:
        name: "Toov"

      android:
        applicationId: "com.example.toov.app.app"
        firebase:
          config: "config/production/google-services.json"
      ios:
        bundleId: "com.example.toov.app"
        firebase:
          config: "config/production/GoogleService-Info.plist"
  ide: "idea"

After launch flutter pub run flutter_flavorizr i run app (with launch view) without a problem. But, after i add in app the firebase authentication, on run app return this error

  E/flutter (26119): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
E/flutter (26119): #0      MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:193:5)
E/flutter (26119): #1      Firebase.app (package:firebase_core/src/firebase.dart:56:41)
E/flutter (26119): #2      FirebaseAuth.instance (package:firebase_auth/src/firebase_auth.dart:44:47)
E/flutter (26119): #3      new AuthenticationRepository (package:toover/data/repositories/AuthenticationRepository.dart:20:68)
E/flutter (26119): #4      main (package:toover/main_development.dart:14:36)
E/flutter (26119): #5      _runMain.<anonymous closure> (dart:ui/hooks.dart:131:23)
E/flutter (26119): #6      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:296:19)
E/flutter (26119): #7      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
E/flutter (26119): 

Then i try to add this

await Firebase.initializeApp(name: "App Dev");

but return this:

E/flutter ( 8394): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)
E/flutter ( 8394): #0      FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/flutter ( 8394): <asynchronous suspension>
E/flutter ( 8394): #1      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter ( 8394): <asynchronous suspension>
E/flutter ( 8394): #2      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter ( 8394): <asynchronous suspension>
E/flutter ( 8394): #3      main (package:toover/main_development.dart:14:3)
E/flutter ( 8394): <asynchronous suspension>
E/flutter ( 8394): 

i call the instance of FirebaseAuthentication with firebase_auth.FirebaseAuth.instance;

i forgot to configure something?

Thanks

AngeloAvv commented 1 year ago

Hello @jempis, simply instantiate Firebase without passing any params:


await Firebase.initializeApp();
jempis commented 1 year ago

Hi @AngeloAvv , thank for response but with passing or not any params when call Firebase.initializeApp(), the error is the same

E/flutter ( 8504): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)
E/flutter ( 8504): #0      FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/flutter ( 8504): <asynchronous suspension>
E/flutter ( 8504): #1      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter ( 8504): <asynchronous suspension>
E/flutter ( 8504): #2      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter ( 8504): <asynchronous suspension>
E/flutter ( 8504): #3      main (package:toover/main_development.dart:15:3)
E/flutter ( 8504): <asynchronous suspension>
E/flutter ( 8504): 
mafreud commented 1 year ago

@AngeloAvv This worked for me. Thank you.

Hello @jempis, simply instantiate Firebase without passing any params:

await Firebase.initializeApp();
AngeloAvv commented 1 year ago

@jempis sounds like you forgot to add dependencies in the build.gradle files.

jempis commented 1 year ago

Sorry @AngeloAvv , but what are this dependencies? there aren't this dependencies in the tutorial..

AngeloAvv commented 1 year ago

@jempis you have to follow the one without flutterfire CLI: https://firebase.flutter.dev/docs/manual-installation

yacine-h-brahim commented 8 months ago
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  Platform.isAndroid
      ? await Firebase.initializeApp(
          options: FirebaseOptions(
            apiKey: "ApiKey",
            appId: "AppId",
            messagingSenderId: "MessagingSenderId",
            projectId: "ProjectId",
          ),
        )
      : await Firebase.initializeApp();

  runApp(const MainApp());
}

-follow this youtube video for more: https://www.youtube.com/watch?v=Qn2ysnVMvEE -happy coding.