Android GCM with product flavors

I have GCM sample android gradle project. Its worked well, when I add 2 flavors a push notification stopped to work. My compilation manifest (it’s taken from app\build\intermediates\manifests\ex\debug) file is below:

<manifest xmlns:android=""
    <uses-permission android:name="" />

        android:protectionLevel="signature" />

            android:permission="" >
                <action android:name="" />
                <action android:name="" />

                <category android:name="" />

        <service android:name="" />
            class=".AppLocationService" >
                    android:value=".AppLocationService" />

What should I do to fix this problem? Please help.

  • how to rotate a bitmap 90 degrees
  • Android Gradle build : renaming the apk
  • Set drawable resource ID in android:src for ImageView using data binding in Android
  • How can I call getContentResolver in android?
  • Slideshow in android viewpager?
  • Replacing the standard Android H264 software encoder with an ffmpeg based one
  • UPD1. I am using gradle v.0.12+. i think my final manifest file looks good, GCMRegistrar.checkManifest(this); – without errors, but GCMRegistrar.isRegistered(this) always false. =(

    UPD2. My first flavor project with original package name (as project in main branch) works well, but second flavor with changed package doesn’t work (registrationId for push is still empty), but in manifest file all permitions are correct.

    Related posts:

    How can restrict my EditText input to some special character like backslash(/),tild(~) etc by soft k...
    Does Proguard guarantee to provide the same mapping if no source has changed?
    Android ADB didn&#039;t ack issue in eclipse
    Android Volley + JSONObjectRequest Caching
    Make new activity appear behind old one during transition
    &ldquo;The signing configuration should be specified in Gradle build scripts&rdquo;&hell...
  • SDK Location not found in android studio
  • Android Studio : how to create hotkey to clear logcat?
  • When to use an aidl based service?
  • Android: Possible to start multiple instances of an Activity in same task?
  • Android: How to broadcast intent from native code?
  • When call initLoader in Fragment?
  • 3 Solutions collect form web for “Android GCM with product flavors”

    Simpy use the ${applicationId} alias like this

    <permission android:name=            "${applicationId}.permission.C2D_MESSAGE"
                android:protectionLevel= "signature" />
    <uses-permission android:name=       "${applicationId}.permission.C2D_MESSAGE" />
    <uses-permission android:name=       "" />

    And for the corresponding receiver use this

            android:name = ""
            android:permission = "">
                <action android:name = ""/>
                <action android:name = ""/>
                <category android:name = "${applicationId}"/>

    I found solution in this post GCM not registering when changing package name with Gradle. I just override BroadcastReceiver, if anyone can explain why it helpes please tell me.

    add following code in apps build.gradle which will copy selected flovour json file to app folder.

    gradle.taskGraph.beforeTask { Task task ->
            if( ==~ /process.*GoogleServices/) {
                android.applicationVariants.all { variant ->
                    if( ==~ /(?i)process${}GoogleServices/){ 
                        copy {
                            from "/src/${variant.flavorName}"
                            into '.'
                            include 'google-services.json'
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.