최근 앱 업데이트에서 targetSdkVersion 을 기존에 30에서 31로 올렸다.
플레이스토어 게시하고 하루만에 1만건이 넘는 크래시 리포트가 접수되었다. ㅠ.ㅜ
아래는 에러 로그.
Fatal Exception: java.lang.IllegalArgumentException
kr.connect.touch.joins: 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.
PendingIntent 인텐트 사용시 플래그에 FLAG_IMMUTABLE 이나 FLAG_MUTABLE 을 사용해야 한다.
적용하기 위해서는 gradle 파일의 디펜던시에 라이브러리를 추가한다.
implementation 'androidx.work:work-runtime-ktx:2.7.1'
그리고 PendingIntent를 사용하는 부분에서 flag를 수정한다.
val contentIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.getActivity(
this,
statusBarNotifications.hashCode(),
statusBarNotifications,
PendingIntent.FLAG_MUTABLE
)
} else {
PendingIntent.getActivity(
this,
statusBarNotifications.hashCode(),
statusBarNotifications,
PendingIntent.FLAG_UPDATE_CURRENT
)
}
저걸로 끝난줄 알았는데...
앱이 백그라운드에 있는 동안 푸시를 수신하면 계속 같은 에러가 발생한다.
도무지 어디서 문제인지 찾기가 너무 어렵다.
에러 로그를 한참 째려보고 'firebase-messaging' 라이브러리와 관련한 부분에서 문제가 발생하는것 같다.
그래서 'firebase-bom'의 버전을 업그레이드 한다.(기존엔 26을 사용했다.)
implementation platform('com.google.firebase:firebase-bom:28.0.0')
이제 백그라운드에 있는 동안 푸시를 수신해도 문제가 없다.
[참고 자료]
https://keelim.tistory.com/entry/안드로이드-SDK-31-대응-사항-중-PendingIntent-에-관하여
https://hckim999.tistory.com/45
'개발 > 안드로이드' 카테고리의 다른 글
Firebase DynamicLink 오류(삼성브라우저에서) (0) | 2022.06.28 |
---|---|
Google Play Developer API 실시간 개발자 알림 구현 (0) | 2022.06.07 |
[오류] firebaseinstanceid: token retrieval failed: service_not_available. will retry token retrieval (0) | 2022.02.22 |
OnlyVerticalSwipeRefreshLayout (0) | 2022.02.21 |
그룹의 전화번호 가져오기 (0) | 2016.03.17 |