如何配置Flutter Firebase的平台。

huangapple go评论71阅读模式
英文:

How to configure platforms for flutter firebase

问题

我正在遵循此指南 来配置 Flutter 应用程序的 Firebase。

flutterfire configure 对我来说失败了,无论是在 Flutter 的主要版本还是稳定版本上都失败了。

可能出了什么问题?

以下是生成的 firebase_options.dart

// File generated by FlutterFire CLI.
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
    show defaultTargetPlatform, kIsWeb, TargetPlatform;

/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
///   options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
  static FirebaseOptions get currentPlatform {
    if (kIsWeb) {
      throw UnsupportedError(
        'DefaultFirebaseOptions have not been configured for web - '
        'you can reconfigure this by running the FlutterFire CLI again.',
      );
    }
    switch (defaultTargetPlatform) {
      case TargetPlatform.android:
        return android;
      case TargetPlatform.iOS:
        return ios;
      case TargetPlatform.macOS:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for macos - '
          'you can reconfigure this by running the FlutterFire CLI again.',
        );
      case TargetPlatform.windows:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for windows - '
          'you can reconfigure this by running the FlutterFire CLI again.',
        );
      case TargetPlatform.linux:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for linux - '
          'you can reconfigure this by running the FlutterFire CLI again.',
        );
      default:
        throw UnsupportedError(
          'DefaultFirebaseOptions are not supported for this platform.',
        );
    }
  }

  static const FirebaseOptions android = FirebaseOptions(
    apiKey: 'AIzaSyDol6n8GLn8HT5P4xl22GdC4x8XAdNM8PA',
    appId: '1:170500034711:android:057f7c563f4d02324399d2',
    messagingSenderId: '170500034711',
    projectId: 'date-game-com',
    storageBucket: 'date-game-com.appspot.com',
  );

  static const FirebaseOptions ios = FirebaseOptions(
    apiKey: 'AIzaSyDuvrG6zSBknSVqhQnC62HGz6-47Tw2o-A',
    appId: '1:170500034711:ios:38716b467804b00f4399d2',
    messagingSenderId: '170500034711',
    projectId: 'date-game-com',
    storageBucket: 'date-game-com.appspot.com',
    iosClientId: '170500034711-djeuqsd9gt4roqrau95irc8aakntn5kl.apps.googleusercontent.com',
    iosBundleId: 'com.date-game.RunnerTests',
  );
}
英文:

I am following the guidance to configure firebase for flutter application.

flutterfire configure fails for me, with both master and stable channels of flutter.

What can be wrong?

i Found 5 Firebase projects. Selecting project date-game-com.                                                                                                                   
✔ Which platforms should your configuration support (use arrow keys & space to select)? · android, ios                                                                          
✔ Which Android application id (or package name) do you want to use for this configuration, e.g. 'com.example.app'? · com.dategame                                              
i Firebase android app com.dategame registered.                                                                                                                                 
i Firebase ios app com.date-game.RunnerTests registered.                                                                                                                        
✔ Generated FirebaseOptions file lib/firebase_options.dart already exists, do you want to override it? · yes                                                                    
Unhandled exception:
FormatException: Unexpected end of input (at character 1)
^
#0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
#1      _ChunkedJsonParser.close (dart:convert-patch/convert_patch.dart:501:7)
#2      _parseJson (dart:convert-patch/convert_patch.dart:36:10)
#3      JsonDecoder.convert (dart:convert/json.dart:610:36)
#4      FirebaseAndroidOptions.projectIdFromFileContents (package:flutterfire_cli/src/firebase/firebase_android_options.dart:29:29)
#5      FirebaseAndroidGradlePlugins.applyGoogleServicesPlugin (package:flutterfire_cli/src/firebase/firebase_android_gradle_plugins.dart:101:50)
<asynchronous suspension>
#6      FirebaseAndroidGradlePlugins.apply (package:flutterfire_cli/src/firebase/firebase_android_gradle_plugins.dart:240:5)
<asynchronous suspension>

Here is generated firebase_options.dart:

// File generated by FlutterFire CLI.
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;
/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
///   options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for web - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.windows:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for windows - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}
static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyDol6n8GLn8HT5P4xl22GdC4x8XAdNM8PA',
appId: '1:170500034711:android:057f7c563f4d02324399d2',
messagingSenderId: '170500034711',
projectId: 'date-game-com',
storageBucket: 'date-game-com.appspot.com',
);
static const FirebaseOptions ios = FirebaseOptions(
apiKey: 'AIzaSyDuvrG6zSBknSVqhQnC62HGz6-47Tw2o-A',
appId: '1:170500034711:ios:38716b467804b00f4399d2',
messagingSenderId: '170500034711',
projectId: 'date-game-com',
storageBucket: 'date-game-com.appspot.com',
iosClientId:
'170500034711-djeuqsd9gt4roqrau95irc8aakntn5kl.apps.googleusercontent.com',
iosBundleId: 'com.date-game.RunnerTests',
);
}

答案1

得分: 2

我通过停用然后重新启用 flutter-fire 并删除 Google services.json 文件来修复了它,但不确定到底发生了什么。

dart pub global deactivate flutterfire_cli
dart pub global activate flutterfire_cli
英文:

I fixed it by deactivating and reactivating flutter-fire and deleting Google services.json file but not sure exactly what is happening

dart pub global deactivate flutterfire_cli
dart pub global activate flutterfire_cli

huangapple
  • 本文由 发表于 2023年6月26日 03:48:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76552168.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定