-2

I have a project with a lot of build types and 2 product flavors.
I've integrated FCM into my project, but I want to enable them only for some build types. To enable FCM, I have to add apply plugin: 'com.google.gms.google-services' into my module-level build.gradle. According to this answer, I can't enable plugin only for certain build type.

All my build types have different package names, and I have generated google-services.json only for packages, which should use FCM.

So finally a question: How to enable (disable) FCM for certain build type?

Vladyslav Matviienko
  • 10,610
  • 4
  • 33
  • 52

1 Answers1

0

You can manage it by defining conditioning on build flavours on your application class like below.

 if (BuildConfig.DEBUG) {
        FirebaseMessaging.getInstance().setAutoInitEnabled(true);
    } else {
        FirebaseMessaging.getInstance().setAutoInitEnabled(false);
    }

With above solutions you can enable and disable FCM by build flavours.

You can also refer this link for batter solution : https://firebase.google.com/docs/cloud-messaging/android/client

Thanks.

Sagar Kacha
  • 8,338
  • 4
  • 18
  • 27
  • that's right, but it won't even compile if I try to apply the plugin to the build type with a package name, which isn't present in `google-services.json` – Vladyslav Matviienko Apr 24 '18 at 09:53
  • @VladyslavMatviienko No need to apply this plug in to build type. Just apply this plug in as we are generally integrating. – Sagar Kacha Apr 24 '18 at 09:59
  • And in that case I will get `No matching client found for package name 'buildtype.package.name'` because I didn't generate `google-services.json` for the build types I'm not going to use FCM in – Vladyslav Matviienko Apr 24 '18 at 10:04