0
votes

I have an app which I need to add different flavors, and each flavor must have the google-services.json file from firebase. It means that now I manually register a new application, download the json file and put it in the flavor project (folder).

Is there any API for registering the flavor app (different package name) manually, downloading it, and put it in the correct folder, during the gradle build process, by using gradle tasks?

1
It is possible to have single google-services.json file which contains details for multiple "apps"....another option I've used is to create FirebaseApp instance dynamically.John O'Reilly
hi, thanks for your reply, but my question was how to do the register process automatically? can you give more details about the second option? :)Elior
More details on second option in answer below.John O'Reilly

1 Answers

1
votes

As an alternative to using google-services.json (and associated gradle plugin) you can create FirebaseApp instance dynamically using something like:

    FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
            .setApiKey(apiKey)
            .setApplicationId(context.getString(R.string.google_app_id))
            .setDatabaseUrl(databaseUrl)
            .setStorageBucket(storageBucket)
            .build();

    FirebaseApp firebaseApp = FirebaseApp.initializeApp(context, firebaseOptions, "MyApp");