pusher / push-notifications-android

Android SDK for Pusher Beams
https://www.pusher.com/beams
MIT License
21 stars 21 forks source link

Android 12 Incompatibility - lack of "android:exported" declaration #123

Closed developer-dmp closed 2 years ago

developer-dmp commented 2 years ago

Output from Android Studio when upgrading project to target Android 12: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined.

I noticed, even in latest release (1.7.0), that this error was being caused by this library. In order for my project to compile, I had to copy and paste elements from this Manifest into my own to override certain values. My Manifest file now contains this:

<activity
    android:name="com.pusher.pushnotifications.reporting.OpenNotificationActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="com.pusher.pushnotifications.OPEN_TRACKING" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

<service
    android:exported="true"
    android:name="com.pusher.pushnotifications.fcm.EmptyMessagingService">
    <intent-filter android:priority="1">
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

Notice how both elements have the android:exported field explicitly set. Once I updated my Manifest to look like this, the project compiles fine and runs as expected. I have both of the values set to true for the time being, but this should be something that is implemented in the library's Manifest.

benjamin-tang-pusher commented 2 years ago

You're right, I got a similar error message Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present

I will see about changing this.

akaita commented 2 years ago

I already put it in the PR, but just to make it a bit easier I'll repeat it here. When these things happen, you can use tools:node="merge" and avoid having to override the whole manifest entry.

Here, for example:

        <!-- Fixes to Pusher to support Android 12 -->
        <service
            android:name="com.pusher.pushnotifications.fcm.EmptyMessagingService"
            android:exported="false"
            tools:node="merge" />
        <activity
            android:name="com.pusher.pushnotifications.reporting.OpenNotificationActivity"
            android:exported="false"
            tools:node="merge" />