GCM注册重新包装后的舱单失败 [英] GCM registration failing after repackaging manifest

查看:160
本文介绍了GCM注册重新包装后的舱单失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建我的应用程序自定义生成,我可以用我的生产应用程序安装并排侧。

I'm trying to create a custom build of my app that I can install side-by-side with my production app.

我已经成功地重新包装清单与AAPT按<一个拿到我的自定义升级版本,安装并排侧href=\"http://stackoverflow.com/questions/17287018/changing-application-package-name-in-custom-ant-build-step/17287287#17287287\">this回答。我的问题是与得到GCM为这两个应用工作。

I've successfully got my custom staging version to install side-by-side by repackaging the manifest with AAPT as per this answer. My problem is with getting GCM to work for both apps.

我称之为 GCMRegistrar.register ,但我似乎从来没有对应用程序的升级版本的响应(GCM通知仍然正常工作在应用的量产版)。

I call GCMRegistrar.register, but I never seem to get a response to the staging version of the app (GCM notifications still work fine for the production version of the app).

我在我的谷歌Play开发人员帐户创建了一个新的应用程序草案(我想测试应用内结算所以需要托管的应用程序如在谷歌草案播放),并在我的谷歌API的控制台一个新项目分期应用。

I've created a new Draft app in my Google Play developer account (I want to test in-app billing so need to host the app as a Draft in Google Play), and a new Project in my Google APIs Console for the staging app.

我试图用看起来就像这样的域:

The domains I'm trying to use look like this:


  • 生产= com.mydomain.myapp <​​/ li>
  • 分期= com.mydomain.myapp.staging

我打的第一个问题是,AAPT不改变GCM权限,因此GCM会失败:

The first problem I hit was that AAPT doesn't change the GCM permissions, so GCM would fail with:

Application does not define permission com.mydomain.myapp.staging.permission.C2D_MESSAGE

所以我添加自定义生成步骤进一步更新我的Andr​​oidManifest.xml。下面是相关的部分现在:

So I added a custom build step to update my AndroidManifest.xml further. Here are the relevant sections now:

<manifest 
    ...
    package="com.mydomain.myapp">

    <permission
        android:name="com.mydomain.myapp.staging.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.mydomain.myapp.staging.permission.C2D_MESSAGE" />

    <permission
        android:name="com.mydomain.myapp.staging.MESSAGING_PERMISSION"
        android:label="Blah"
        android:protectionLevel="normal" >
    </permission>

    <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="com.mydomain.myapp" />
        </intent-filter>
    </receiver>

&LT;&许可GT; 标签,似乎需要新的软件包名称,以避免我上面提到的错误。

The <permission> tags seem to require the new package name to avoid the error I mentioned above.

主要&LT;&舱单GT; 标记需要保持原有的包名,否则该应用程序崩溃。这是因为重新包装需要在安装点动态地发生(例如,如果你重新包装你会看到这个包的名字是不变后,反编译你的应用程序),所以你不应该改变的包名的此实例。

The main <manifest> tag needs to keep the original package name, otherwise the app crashes. This is because the repackaging seems to happen dynamically at the point of install (i.e. if you decompile your app after repacking you'll see this package name is unchanged), so you shouldn't change this instance of the package name.

我不知道如果最终&lt;接收方式&gt; 应该是原件或重新打包的名字,但我都试过既不似乎工作

I'm not sure if the final <receiver> should be the original or the repackaged name, but I've tried both and neither seem to work.

下面从谷歌API控制台API访问的信息:

Here the API Access information from the Google APIs Console:

STAGING
Key for Android apps (with certificates)
API key: <key>
Android apps: <SHA1>;com.mydomain.myapp.staging

PRODUCTION
Key for Android apps (with certificates)
API key: <key>
Android apps: <SHA1>;com.mydomain

双方也有一个支持浏览器的应用程序键(与参照网址)。

Both also have a "Key for browser apps (with referers)".

我不知道如果面向Android应用密钥实际上是必需的,但在GCM文档使它有点难以明白这一点。

I'm not sure if the "Key for Android apps" is actually required, but the GCM docs make it a bit hard to figure that out.

有没有人有什么想法?我想知道,如果键Android应用引起的问题,或者事实证​​明我的分期应用是生产应用程序的一个子域。

Has anybody got any ideas? I was wondering if the "Key for Android apps" is causing the problem, or perhaps the fact that my staging app is a subdomain of the production app.

另外一个难题是需要多长时间从谷歌API的控制台更改传播 - 有谁知道我需要多久重新测试,以确保在变化在发生之前等待

One other complication is how long it takes changes from the Google APIs Console to propagate - does anybody know how long I need to wait before retesting to be sure the changes are in place?

推荐答案

我不知道如何 AAPT 的作品,但我知道如何清单应GCM定义

I'm not sure how AAPT works, but I know how the manifest should be defined for GCM.

所有的地方,下面标注 PACKAGE 应包含相同的包名。

All the places marked below with PACKAGE should contain the same package name.

<manifest 
    ...
    package="PACKAGE">

<permission
    android:name="PACKAGE.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="PACKAGE.permission.C2D_MESSAGE" />

<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="PACKAGE" />
    </intent-filter>
</receiver>

另一个问题可能是你的意图的服务。如果您使用的是扩展服务类 GCMBaseIntentService GCMBroadCastReceiver 查找此类应用程序的主包,因此,在您升级版本,它有不同的软件包名称,也不会发现它。

Another problem could be your intent service. If you are using a service class that extends GCMBaseIntentService, GCMBroadCastReceiver looks for this class in the main package of the app, so in your staging version, which has a different package name, it won't find it.

在这种情况下,解决方法是使用一个子类 GCMBroadCastReceiver ,并忽略指定服务类的路径方法。

The solution in this case is to use a sub class of GCMBroadCastReceiver and override the method that specifies the path of your service class.

我的答案<一个href=\"http://stackoverflow.com/questions/17212275/register-gcm-from-a-library-project/17216192#17216192\">here是关系到你的问题。

My answer here is related to your problem.

这篇关于GCM注册重新包装后的舱单失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆