I have a module in Android Studio that I'm using across several apps (all signed with different keys) that handles GCM notifications.
In the GCM Client documentation they say to define package namespaced custom permissions:
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
and then again with the GCM receiver the category
is set to the package name:
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
Currently I have all these defined in the module's Manifest and it gets merged by gradle into the app manifest of whatever app is importing this module with a generic namespace for that module, and this has worked so far.
The problem is that since Android 5.0 custom permissions are matched against the keystore that the app was signed with. If you have one app with this module installed, it won't let you install another with the same module in it because the permissions conflict.
Is there a way to declare the C2D_MESSAGE
permissions and the BroadcastReceiver
within the module so that it doesn't need to be redefined in each app?
[Update]
I've tried using placeholders in the library's manifest with mixed results. Using ${applicationId}
results in that library's package name getting substituted rather than the consuming app's package name.
Reading this and its related issues led me to use ${localApplicationId}
with it defined in the consuming app's build.gradle:
defaultConfig {
manifestPlaceholders = [ localApplicationId:"com.testapp.client"]
applicationId 'com.testapp.client'
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName '1.0'
}
productFlavors {
flavor {
applicationId "com.testapp.client.flavor"
manifestPlaceholders = [ localApplicationId:"com.testapp.client.flavor"]
}
}
results in error:
Error:(12, 22) Attribute uses-permission#${localApplicationId}.permission.C2D_MESSAGE@name at AndroidManifest.xml:12:22 requires a placeholder substitution but no value for <localApplicationId> is provided.