1

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

KK_07k11A0585
  • 2,381
  • 3
  • 26
  • 33

2 Answers2

3

Solutions to android 12 migration

In Android 12 , there are some major code changes we need to do :

  • We need to export all activities and other app components, we need to make the launcher as exported true android:exported="true"

  • we need to set either immutable or mutable flags to our pending intents objects.

    val intent = Intent(this, AlarmReceiver::class.java) val pendingIntent = PendingIntent.getBroadcast( this, ALARM_SERVICE_CODE, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT )

I recently migrated my apps and I listed complete migration journey with the solution to these crashes here

solutions: https://medium.com/native-mobile-bits/lets-use-android-12-migration-of-our-android-apps-to-android12-api-31-af329b6829d0

solutions: I have also shown my project migration to Android 12 at my Youtube. where i fix all these issues here https://www.youtube.com/watch?v=X9IfLFLaVKI

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
2

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

KK_07k11A0585
  • 2,381
  • 3
  • 26
  • 33