androidbroadcastreceiverandroid-serviceandroid-pendingintenttargetsdkversion

Android 12 targetSDKVersion 31 challenges (Broadcast Receiver, Pending Intent) Crash Issues


Below are the challenges I faced so far when running an Android app with targetSDKVersion 31 on a phone with OS Version Android 12

1) App is not getting uploaded to store Error :- You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without the 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#exported

2) App is getting crashed java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. FLAG_IMMUTABLE / FLAG_MUTABLE tag is required for all Pending Intents

Please help how to address these issues ????


Solution

  • 1) App is not getting uploaded to store Error :- You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without the 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#exported

    Solution :- Targeting from 12, If in case any of your activity/service/receiver in your AndroidManifest.xml of your app or in any library is using intent-filter then it should have android:exported tag specified explicitly. You can select the MergerManifest option in AndroidManifest.xml to identify which library has Services and Activities.

    2) App is getting crashed java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. FLAG_IMMUTABLE / FLAG_MUTABLE tag is required for all Pending Intents

    Solution:- Add FLAG_IMMUTABLE for all the PendingIntents. If your PendingIntent already has a flag then append this by using |. Eg:- FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE, FLAG_CANCEL_CURRENT | FLAG_IMMUTABLE