Android 5.0 - Declaring custom permissions in a module

I have a module in Android Studio that I use in several applications (all signed with different keys) that handle GCM notifications.

The GCM client documentation says to define custom permissions with package name expansion:

<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 category

set 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>

      

I currently have it all defined in the Manifest module and it gets merged with gradle into the app manifest when any app imports that module with a common namespace for that module and it works so far.

The problem is because Android 5.0 custom permissions map to the keystore the app was signed with. If you have one app with a module installed, it won't let you install another one with the same module because of permission conflicts.

Is there a way to declare the resolution C2D_MESSAGE

and the BroadcastReceiver

inside of the module so that it did not need to override in each application?

[Update]

I've tried using placeholders in the library manifest with mixed results. Usage ${applicationId}

results in the library package name being replaced rather than the application package name to use.

Reading this and related issues made me use ${localApplicationId}

with it defined in build.gradle build app:

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 an 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.

      

+3


source to share





All Articles