[英]Multiple Builds Environment in Flutter for Firebase Using buildTypes (multiple google-services.json)
I created multiple firebase project in one app to separate the development and production environment, so now I have 2 different generated google-services.json.我在一个应用程序中创建了多个 firebase 项目来分离开发和生产环境,所以现在我有 2 个不同的生成 google-services.json。 I want to be able to run/build using a specific environment by specifying buildTypes as mentioned in this article on step 3 .我希望能够通过指定本文第 3 步中提到的 buildTypes 来使用特定环境运行/构建。 So my app folder below will follow this article.所以我下面的应用程序文件夹将遵循这篇文章。
NOTE: Why don't I use flavor?注意:为什么我不使用味道? Because I already use command arguments (--dart-define).因为我已经使用了命令参数(--dart-define)。
This is snippet of my buildTypes:这是我的 buildTypes 的片段:
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
}
}
I delete apply plugin: 'com.google.gms.google-services'
as stated in this documentation .我删除了apply plugin: 'com.google.gms.google-services'
如本文档所述。
This is my app folder:这是我的应用程序文件夹:
I run my project using debug build ( flutter run --debug
) but I got this error:我使用调试构建( flutter run --debug
)运行我的项目,但出现此错误:
Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project?
I checked this documentation page on firebase flutter site, it mentioned:我在 firebase flutter 网站上查看了这个文档页面,它提到:
await Firebase.initializeApp(
name: 'SecondaryApp',
options: const FirebaseOptions(
appId: 'my_appId',
apiKey: 'my_apiKey',
messagingSenderId: 'my_messagingSenderId',
projectId: 'my_projectId'
)
);
is my choice only passing all required data via command arguments using this approach?我的选择是只使用这种方法通过命令参数传递所有必需的数据吗? I'm afraid it has limitations as I use other Firebase services.恐怕它有局限性,因为我使用其他 Firebase 服务。 Any insights would be nice, thanks.任何见解都会很好,谢谢。
Your google-services.json file is under the incorrect folder.您的 google-services.json 文件位于不正确的文件夹下。 It should be in android/app.它应该在 android/app 中。 Not android/app/src/debug.不是 android/app/src/debug. You can follow this official document .你可以按照这个官方文档。
Once your Android app has been registered, download the configuration file from the Firebase Console (the file is called google-services.json).注册您的 Android 应用后,从 Firebase 控制台下载配置文件(该文件名为 google-services.json)。 Add this file into the android/app directory within your Flutter project.将此文件添加到 Flutter 项目中的 android/app 目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.