简体   繁体   English

如何以编程方式将Firebase Google JSON更改为不同的构建变体?

[英]How to programatically change Firebase google JSON for different build variants?

In general to switch between build variants you can use productFlavors . 通常,可以在productFlavors变体之间进行切换,可以使用productFlavors But I want to change these variants in runtime with button. 但是我想在运行时使用按钮更改这些变体。

There is ServerType enum class containing multiple build variants. ServerType枚举类包含多个构建变体。 I have Server class with apiKey and url attribute. 我有带有apiKeyurl属性的Server类。

Inside those variants are Server objects.(You can use multiple APIs per build variant). 这些变量内部是Server对象。(每个构建变量可以使用多个API)。

This enum class has same functionality as productFlavors . 该枚举类具有与productFlavors相同的功能。 I can change those addresses in runtime and set active variant from dropdown menu. 我可以在运行时更改这些地址,并从下拉菜单中设置活动变量。 This will affect every API call in my app. 这将影响我应用中的每个API调用。 What I cant change is what google.json is chosen by Firebase. 我无法更改的是Firebase选择的google.json Is there any way how to tell Firebase to use different json? 有什么办法告诉Firebase使用不同的json吗? I have 4 variants and jsons are located inside each variant file in project. 我有4个变体,并且jsons位于项目中的每个变体文件内。

Firebase is choosing automatically google.json based on what Build Variant is selected while building the app. Firebase会在Build Variant应用时根据选择的Build Variant自动选择google.json。

Have you tried the multiple environment directories? 您是否尝试过多个环境目录? Which allows you to put several different google.json files for different build variants. 这允许您为不同的构建变体放置几个不同的google.json文件。 ( help from firebase site ). 来自Firebase网站的帮助 )。

This is also a dedicated directory, so not that dynamic, but this is all that the Firebase can handle on runtime. 这也是一个专用目录,因此不是动态目录,而是Firebase在运行时可以处理的所有目录。

The choice of which google-services.json file to use is always determined at build time by the Google play services plugin. 使用哪个google-services.json文件的选择始终由Google Play服务插件在构建时确定。 It is never determined at runtime. 它永远不会在运行时确定。

If you need to change project configurations at runtime, you will not be able to use that plugin or its google-services.json configuration file. 如果您需要在运行时更改项目配置,则将无法使用该插件或其google-services.json配置文件。 You will need to find another way to put all the possible different configurations in your app at build time, then select which one to use at runtime. 您将需要找到另一种在构建时将所有可能的不同配置放入应用程序中的方法,然后选择要在运行时使用的配置。 You will have to call FirebaseApp.initializeApp() yourself instead of accepting the default configuration. 您将必须自己调用FirebaseApp.initializeApp()而不是接受默认配置。 There are a lot of strategies to do this, but I will recommend you start here . 有很多策略可以做到这一点,但是我建议您从这里开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过gradle构建不同的android变种 - how to build different variants of android through gradle Xamarin firebase 不同的 google-services,json 用于不同的构建配置 - Xamarin firebase different google-services,json for different build configurations 不同的“构建变体”使用不同的配置 - Different Configurations for different “Build Variants” 如何针对不同的构建变体使用不同的network-security-config? - How to have different network-security-config for different build variants? 如何在 Flutter Android 中创建构建变体,以便每个构建变体都有不同的应用程序 ID? - How to create build variants in Flutter Android so that each build variants have different app id? 如何创建指向不同服务器的不同构建变体? - How to create different build variants pointing to different Servers? 用于配置构建变体的不同git repo - Different git repo for Configure Build Variants 有没有机会在Android中更改构建变体的运行时间 - Is there a chance to change the build variants run time in android 如何在两个不同的构建变体中使用相同的 package 名称 android 应用程序,但它们的资源不同 - How to use the same package name android app in two different build variants but their resource is different Android Instant App上的多个构建变体的Firebase构建错误 - Firebase build error for multiple build variants on Android Instant App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM