pusher / push-notifications-android

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

Support Android 12 (build tools 31) #124

Closed akaita closed 2 years ago

akaita commented 2 years ago

Solves https://github.com/pusher/push-notifications-android/issues/123

If you target Android 12 when building (targetSdkVersion 31), you get this error:

Manifest merger failed : android:exported needs to be explicitly specified for <activity>. 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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

You need to set android:exported for everything that has an intent in the manifest.

note: as a workaround I set this in my apps' AndroidManifest.xml, but I should not:

        <!-- 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" />
marcelcorso commented 2 years ago

hey @akaita! Thank you for the PR.

Can you help me a little bit to understand this change (I'm not an Android dev)?

My question is whether this will have an impact on other users of the sdk. The docs say that android:exported practical default is already to false... We do define a intent-filter there. Do you think other people could be using this?

marcelcorso commented 2 years ago

๐Ÿ‘‹ @Oleur, @obuiron and @YvesDelerm

you guys gave an upvote. Maybe you can help me with my question? ๐Ÿ™

Oleur commented 2 years ago

๐Ÿ‘‹ @Oleur, @obuiron and @YvesDelerm

you guys gave an upvote. Maybe you can help me with my question? ๐Ÿ™

Hi @marcelcorso ! Happy to tell you more about that :)

According to the documentation to support Android 12: If your app targets Android 12 and contains activities, services, or broadcast receivers that use intent filters, you must explicitly declare the android:exported attribute for these app components.

The Pusher libraries defines a Service and an Activity that are not yet compliant. Without specifying the exported attributes in the library, we are not able to compile our apps that target Android 12.

Feel free to ping if you need more details about that!

marcelcorso commented 2 years ago

@Oleur thank you. I understand better now.

My question is: If we make explicitly android:exported = false can it cause problems to users of the library that are upgrading?

Oleur commented 2 years ago

No problems should appear as the components are already android:exported = false but implicitly :)