Firebase 2.0 - how to deal with multiple flavors (environments) of an android app?

后端 未结 2 1136
孤独总比滥情好
孤独总比滥情好 2020-12-08 13:53

I have multiple flavors of my app. How should I set this up server side? My package names are:

com.example.app (production) com.example.app.stagin

2条回答
  •  感动是毒
    2020-12-08 14:26

    Note I didn't fully try this yet, but documenting it here to not lose it until I get to it.

    One actually isn't forced to use the gradle plugin, which enforces you to have a firebase project for all of your flavors and build types.

    This is poorly documented, but one can find a hint at the top of the documentation for FirebaseApp and some more at https://firebase.google.com/docs/configure/

    Alternatively initializeApp(Context, FirebaseOptions) initializes the default app instance. This method should be invoked from Application. This is also necessary if it is used outside of the application's main process.

    So, fetch the google-services.json as usual and from it take mobilesdk_app_id and current_key (under api_key), that should be all that's needed for Google Analytics tracking at least. With that information run the following in your app's Application subclass for the variants where you need it:

    FirebaseOptions options = new FirebaseOptions.Builder()
      .setProjectId("")
      .setApplicationId("")
      .setApiKey("")
      .build();
    FirebaseApp.initializeApp(this, options);
    

提交回复
热议问题