Skip to content Skip to sidebar Skip to footer

Gcm Not Registering When Changing Package Name With Gradle

In my regular build gcm works fine, but when I use flavors to change the com name things stop working. My IntentService is never being initialized. How should I set up my manifes

Solution 1:

This was my solution:

<permissionandroid:name="com.sample.app.permission.C2D_MESSAGE"android:protectionLevel="signature" /><uses-permissionandroid:name="com.sample.app.permission.C2D_MESSAGE" />

...

<serviceandroid:name=".GCMIntentService" /><receiverandroid:name=".MyBroadcastReceiver"android:permission="com.google.android.c2dm.permission.SEND" ><intent-filter><actionandroid:name="com.google.android.c2dm.intent.RECEIVE" /><actionandroid:name="com.google.android.c2dm.intent.REGISTRATION" /><categoryandroid:name="com.sample.app" /></intent-filter></receiver>

in my manifest and mybroadcastReceiver

...

publicclassMyBroadcastReceiverextendsGCMBroadcastReceiver
   {
    @OverrideprotectedStringgetGCMIntentServiceClassName(Context context)
    {
        returnGCMIntentService.class.getName();
    }
    }

Solution 2:

From your manifest it looks like your app's package name is com.sample.app, which is consistent with your permission.C2D_MESSAGE definition. Your receiver's intent filter's category says ${packageName}. Hopefully that gets translated to com.sample.app too, as it should.

Other than that, your log posted above shows that your intent service is expected to be at com.sample.app.dev.GCMIntentService. That's a different package.

You seem to be using the old deprecated GCM client library, in which com.google.android.gcm.GCMBroadcastReceiver expects the intent service to be called GCMIntentService and be located in the main package of the app :

/**
 * Gets the default class name of the intent service that will handle GCM
 * messages.
 */static final StringgetDefaultIntentServiceClassName(Context context) {
    String className = context.getPackageName() +
            DEFAULT_INTENT_SERVICE_CLASS_NAME;
    return className;
}

Your manifest declares the intent service class to be in the main package of your app :

<service android:name=".GCMIntentService" />

All these things don't add up. Either your app's package name is com.sample.app.dev or com.sample.app. If it's the former, the manifest you posted is incorrect. If it's the latter, there is no reason for the broadcast receiver to expect the intent service class to be com.sample.app.dev.GCMIntentService.

Post a Comment for "Gcm Not Registering When Changing Package Name With Gradle"