当前位置: 首页 > 知识库问答 >
问题:

如何共享链接到 Firebase 的项目的 Flutter 源代码?

淳于博
2023-03-14

我有一个链接到我的Firebase帐户的Flutter项目(使用< code>FlutterFire CLI)。< br >现在我已经完成了这个项目,我想卖掉源代码。< br >如何更改与此项目关联的Firebase帐户?

当使用FlutterFire CLI时,它会生成一个名为firebase_options的文件。dart包含每个平台的Firebase选项,如下所示:

static const FirebaseOptions android = FirebaseOptions(  
 apiKey: '-------',  
 appId: '------',  
 messagingSenderId: '-----',  
 projectId: '----------',  
 storageBucket: '--------',  
  );

我必须改变这些值吗?如果是,我在哪里可以找到所有这些?

import 'firebase_options.dart';


void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  runApp(const MyApp());
}
// 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) {
      return web;
    }
    switch (defaultTargetPlatform) {
      case TargetPlatform.android:
        return android;
      case TargetPlatform.iOS:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for ios - '
          'you can reconfigure this by running the FlutterFire CLI again.',
        );
      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 web = FirebaseOptions(
    apiKey: '------',
    appId: '------',
    messagingSenderId: '-----',
    projectId: '------',
    authDomain: '--------',
    storageBucket: '--------',
    measurementId: '--------',
  );

  static const FirebaseOptions android = FirebaseOptions(
    apiKey: '----',
    appId: '----',
    messagingSenderId: '--------',
    projectId: '------',
    storageBucket: '--------',
  );
}

我试图更改值(在firebase_options.dart中),这导致了此错误:

E/flutter (26545): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/duplicate-app] A Firebase App named "[DEFAULT]" already exists

它抛出此错误(来自 method_channel_firebase.dart复制应用程序):

// If there is a native default app and the user provided options do a soft
// check to see if options are roughly identical (so we don't unnecessarily
// throw on minor differences such as platform specific keys missing
// e.g. hot reloads/restarts).
if (defaultApp != null && _options != null) {
  if (_options.apiKey != defaultApp.options.apiKey ||
      (_options.databaseURL != null &&
          _options.databaseURL != defaultApp.options.databaseURL) ||
      (_options.storageBucket != null &&
          _options.storageBucket != defaultApp.options.storageBucket)) {
    // Options are different; throw.
    throw duplicateApp(defaultFirebaseAppName);
  }
  // Options are roughly the same; so we'll return the existing app.
}

共有1个答案

方弘
2023-03-14

您可以更改链接到该项目的firebase帐户。您看到的这个错误

E/flutter (26545): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/duplicate-app] A Firebase App named "[DEFAULT]" already exists

是由原始的gradle sync操作生成一个Google-Services.json文件并在应用程序中使用它引起的。要消除这个错误,从主flutter项目切换到android文件夹并运行

./gradlew clean

该命令调用渐变包装器,然后清理项目并将其恢复到原始状态。flutter团队使用默认的空flatter_options。他们项目的飞镖文件。如果您正在向某人查看源代码,您可能需要考虑这样做。我只会打包说明,说明如何配置他们的项目,以便与他们选择的新Firebase项目一起工作。

 类似资料:
  • 在我的本地开发环境中,我使用Firebase模拟器进行托管、Firestore和其他功能。 我习惯于在开发过程中使用与其他人共享链接。在开发过程中,我还使用它在移动设备上进行测试。 以下是脚本: 它可以很好地重定向到我的dev域主机,即。 但是,当您通过不同的设备(即:不同的PC或移动设备)访问此链接时,模拟器服务将不可用。 显然,包正在寻找那些仅在我的本地环境中运行的模拟器。 这种情况下的解决方

  • 我正在尝试编写一个使用Lame mp3编码器的Android应用程序。我的开发环境是Android Studio 1.1。 根据Lame MP3编码器编译Android下的提示,我成功安装了Android NDK并编译了Lame。在/app/src/main/libs/armeabi下,我获得了共享对象“libmp3lame.so”,其中 libmp3lame.so:ELF 32位LSB共享对象,

  • 标题中的问题。这里提出了一个类似的问题,当时唯一的解决办法是将项目发布到本地Maven存储库中。 这个问题在Android Studio 0.5中修复了吗(正如一些人所声称的)?在其发行说明中有一条声明说“支持模块内容根目录之外的源文件夹”。这是否意味着我们最终可以从项目文件夹外部导入库? 我试过文件- 编辑2:查看最新解决方案的接受答案(截至0.8。) 编辑: 我的项目目录结构只有一个模块,如下

  • 问题内容: 我正在编译一些在Debian Linux系统上使用libcurl的代码。我的开发机正在运行Debian 5,但我也希望二进制文件也可以在较旧的Debian 4系统上使用。 我发现如果指定 -lcurl ,它将链接到libcurl.so.4,但是Debian 4系统仅具有libcurl.so.3 有什么方法可以告诉GCC链接到libcurl.so.3(在Debian 4和5中都存在)还是

  • 我想潜入CN1的Soures。我已经使用Git遵循了这个和这个教程。然而,在NetBeans中,当我用Ctrl键单击CN1对象时,它显示“显示生成的源文件。没有源附加到类'JAR文件‘。”如果我附上我刚刚下载的ie“CodenameOne/CodenameOne/src”的源代码,源代码仍然找不到! 任何帮助都很感激, 问候

  • 我试图将我编译的简单共享库(libhello.so)链接到我的本机C++代码中。库libhello.so文件是: 1。Get13.h 2.get13.cpp Android文件是: 1。myapplication/jni/android.mk 问题是,在gradle构建过程中,我在文件native-lib.cpp中得到了这个错误: 我使用android NDK包中包含的make_standalon