Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用buildTypes(Multiple google services.json)在Flatter中为Firebase构建多个构建环境_Android_Firebase_Flutter - Fatal编程技术网

Android 使用buildTypes(Multiple google services.json)在Flatter中为Firebase构建多个构建环境

Android 使用buildTypes(Multiple google services.json)在Flatter中为Firebase构建多个构建环境,android,firebase,flutter,Android,Firebase,Flutter,我在一个应用程序中创建了多个firebase项目,以分离开发和生产环境,因此现在我有两个不同的生成的google-services.json。我希望能够通过指定BuildType(如中所述)使用特定环境运行/构建。因此,下面我的应用程序文件夹将跟随本文 注意:为什么我不用香精?因为我已经使用了命令参数(-dart define) 这是我的BuildType的片段: buildTypes { debug { signingConfig signingConfigs.debu

我在一个应用程序中创建了多个firebase项目,以分离开发和生产环境,因此现在我有两个不同的生成的google-services.json。我希望能够通过指定BuildType(如中所述)使用特定环境运行/构建。因此,下面我的应用程序文件夹将跟随本文

注意:为什么我不用香精?因为我已经使用了命令参数(-dart define)

这是我的BuildType的片段:

buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        signingConfig signingConfigs.release
    }
}
我删除
应用插件:“com.google.gms.google服务”
,如中所述

这是我的应用程序文件夹:

我使用debug build(
flatter run--debug
)运行项目,但出现以下错误:

Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project?
我在firebase颤振现场进行了检查,它提到:

await Firebase.initializeApp(
    name: 'SecondaryApp',
    options: const FirebaseOptions(
        appId: 'my_appId',
        apiKey: 'my_apiKey',
        messagingSenderId: 'my_messagingSenderId',
        projectId: 'my_projectId'
    )
);

我的选择是否仅使用此方法通过命令参数传递所有必需的数据?由于我使用其他Firebase服务,恐怕它有局限性。任何见解都很好,谢谢。

您的google-services.json文件位于不正确的文件夹下。它应该在android/应用程序中。不是android/app/src/debug。你可以跟着

注册Android应用程序后,从Firebase控制台下载配置文件(该文件名为google services.json)。将此文件添加到Flatter项目中的android/app目录中


我有两个适用于不同环境的google-services.json文件,我想我不能把它放在同一个文件夹中。但假设我编辑了一个google-services.json文件名,如何根据我的构建类型使用特定的google-services.json?好的,您可以按照以下说明操作:哇,谢谢您的好线程,我将测试适合我的用例的几种方法。