使用Gradle更改包名称时GCM无法注册

Qui*_*etz 1 android gradle push-notification google-cloud-messaging android-gradle-plugin

在我的常规构建gcm工作正常,但当我使用flavor改变com名称时,事情就停止了.我的IntentService永远不会被初始化.我应该如何设置我的清单文件以便发生这种情况?

  • 我已将它们添加到开发人员控制台.
  • 我正在使用gradle com.android.tools.build:gradle:0.11.+'

我得到了日志

V/GCMBroadcastReceiver? onReceive: com.google.android.c2dm.intent.REGISTRATION
V/GCMBroadcastReceiver? GCM IntentService class: com.sample.app.dev.GCMIntentService
V/GCMBaseIntentService? Acquiring wakelock
Run Code Online (Sandbox Code Playgroud)

然后什么也没有.我的自定义IntentService类永远不会被初始化,我的registrationId保持为空.我目前的实现类似于这里的实现:https: //stackoverflow.com/a/20334397/198034

我应该如何设置我的清单以获得0.11.+味道与gcm一起使用?

下面是我的一个版本的清单,我在主清单中有更多代码(所有需要的权限等),但没有其他处理gcm.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sample.app"
    android:versionCode="45"
    android:versionName="0.6.5" >

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />


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

    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name" >


        <service android:name=".GCMIntentService" />
        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="${packageName}" />
            </intent-filter>
        </receiver>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

Qui*_*etz 10

这是我的解决方案:

<permission android:name="com.sample.app.permission.C2D_MESSAGE"
     android:protectionLevel="signature" />
 <uses-permission android:name="com.sample.app.permission.C2D_MESSAGE" />
Run Code Online (Sandbox Code Playgroud)

...

<service android:name=".GCMIntentService" />
    <receiver
        android:name=".MyBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.sample.app" />
        </intent-filter>
    </receiver>
Run Code Online (Sandbox Code Playgroud)

在我的清单和mybroadcastReceiver中

...

   public class MyBroadcastReceiver extends GCMBroadcastReceiver
   {
    @Override
    protected String getGCMIntentServiceClassName(Context context)
    {
        return GCMIntentService.class.getName();
    }
    }
Run Code Online (Sandbox Code Playgroud)