0

I have an app which uses Google Services (I'm connecting to Firebase). I now want to set it up with two different flavours - free and paid.

I've done the following in build.gradle:

productFlavors {
    free {
        applicationId "myname.appname.free"
        versionName "1.0-free"
        buildConfigField "boolean", "PAID_VERSION", "false"
    }

    paid {
        applicationId "myname.appname.paid"
        versionName "1.0-paid"
        buildConfigField "boolean", "PAID_VERSION", "true"
    }
}

From what I've read, syncing this should cause Android Studio do something that sets up the code to 'have' 2 flavours, is that right? The problem is, it won't sync - I get the error:

Error:Execution failed for task ':app:processFreeReleaseGoogleServices'.
> No matching client found for package name 'myname.appname.free'

Everything I've read seems to suggest that I get around this by adding google-services.json into the 'free' and 'paid' folders, but those folders don't exist - maybe Android Studio would set them up if it completed the sync?

Also, in the Firebase console, I currently have one app: myname.appname - do I need to create two apps in there, called myname.appname.free and myname.appname.paid? And download a different google-services.json for each?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sharon
  • 3,471
  • 13
  • 60
  • 93

1 Answers1

4

You should follow along with the documentation for the Google Play services plugin.

In particular see the section on Adding the JSON File. You will have to create your own flavor specific directories:

The google-services.json file is generally placed in the app/ directory (at the root of the Android Studio app module). As of version 2.2.0 the plugin supports build type and product flavor specific JSON files. All of the following directory structures are valid:

// dogfood and release are build types.
app/
    google-services.json
    src/dogfood/google-services.json
    src/release/google-services.json
    ...

Note: Providing a google-services.json file in the release directory allows you to maintain a separate Firebase project for your production APKs.

When product flavors are in use these more complicated directory structures are also valid.

// free and paid are product flavors.
app/
    google-services.json
    src/dogfood/paid/google-services.json
    src/release/free/google-services.json
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441