Wednesday, 20 January 2016

Using Parse Android with Build variants and productFlavors

using Parse Android with Build variants and productFlavors

The challenge of this topic is that the packagename of different build variants or flavors will give different package name, e.g the "normal" package name is com.peter.hello, then the "dev" variant will make the package name to com.peter.hello.dev.

if you use dev variant but still use the same AndroidManifest.xml, you will get this error:

01-20 10:00:32.426 15355-15355/? V/com.parse.ManifestInfo: Cannot use GCM for push because the app manifest is missing some required declarations. Please make sure that these permissions are declared as children of the root <manifest> element:
01-20 10:00:32.426 15355-15355/? V/com.parse.ManifestInfo: Using none for push.
V/com.parse.ParsePushChannelsController: Tried to subscribe or unsubscribe from a channel, but push is not enabled correctly. Push is not configured for this app because the app manifest is missing required declarations. Please add the following declarations to your app manifest to use GCM for push: make sure that these permissions are declared as children of the root <manifest> element:

That because your current package name is not com.peter.hello, it is  com.peter.hello.dev.

You can change ".permission.C2D_MESSAGE" in permission section and "category android:name" in the receiver to com.peter.hello.dev. However if you do this change other build variants will be failed as well.

Solution:

1. create different AndroidManifest.xml for different build variants. in each file don't change the package name in the root <manifest> tag, this will be managed by gradle automatically. Just change other places (which are mentioned above).


2. use gradle variables:

As gradle document mentions: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger . You can use variables and gradle will replace them.


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

<category android:name="${packageName}" />











No comments:

Post a comment