Elior
Elior

Reputation: 3266

Automatically generate google-services.json for Android flavor

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?

Upvotes: 0

Views: 1155

Answers (1)

John O'Reilly
John O'Reilly

Reputation: 10330

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");

Upvotes: 1

Related Questions