728x90

안드로이드 targetSdkVersion 31를 변경하였다.

일단 변경을 하지 않으면 스토어에 올라가지 않는다.

변경 후 아래와 같이 크레쉬가 발생하기 시작했다.

Fatal Exception: java.lang.IllegalArgumentException: com.abc.client.traveler: 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.
       at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
       at android.app.PendingIntent.getActivitiesAsUser(PendingIntent.java:616)
       at android.app.PendingIntent.getActivities(PendingIntent.java:598)
       at android.app.TaskStackBuilder.getPendingIntent(TaskStackBuilder.java:275)
       at android.app.TaskStackBuilder.getPendingIntent(TaskStackBuilder.java:249)
       at com.abc.client.traveler.fcm.CmFirebaseMessagingService.makePendingIntent(CmFirebaseMessagingService.kt:218)
       at com.abc.client.traveler.fcm.CmFirebaseMessagingService.sendNotification(CmFirebaseMessagingService.kt:179)
       at com.abc.client.traveler.fcm.CmFirebaseMessagingService.processDataMessage(CmFirebaseMessagingService.kt:128)
       at com.abc.client.traveler.fcm.CmFirebaseMessagingService.onMessageReceived(CmFirebaseMessagingService.kt:82)
       at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@20.3.0:74)
       at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@20.3.0:44)
       at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@20.3.0:27)
       at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@20.3.0:17)
       at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@20.3.0:43)
       at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(:6)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.2.1:6)
       at java.lang.Thread.run(Thread.java:920)

무슨일인가?

  • 일단 아래 런타임 라이브러리를 추가한다.

    implementation 'androidx.work:work-runtime-ktx:2.7.1'
  • 그리고 기존 pendingIntent사용하는 곳을 수정한다, 나는 FLAG_UPDATE_CURRENT 으로 되어있어서 해당값은

  • PendingIntent.FLAG_UPDATE_CURRENT -> PendingIntent.FLAG_IMMUTABLE 으로 변경한다.

변경 전

private fun makePendingIntent(intent: Intent): PendingIntent {

        val stackBuilder = TaskStackBuilder.create(this)
        stackBuilder.addNextIntentWithParentStack(intent)

        return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
    }

변경 후

private fun makePendingIntent(intent: Intent): PendingIntent {

        val stackBuilder = TaskStackBuilder.create(this)
        stackBuilder.addNextIntentWithParentStack(intent)

        return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE)
    }

정상동작하는지 FCM테스트를 진행한다.
잘된다면, 잘 해결된 것이다.

LIST
복사했습니다!