안드로이드 12, java.lang.IllegalArgumentException 오류 수정 방법

2022. 2. 6. 17:37IT/Android

반응형

내 테스트 기기에는 문제가 전~~혀 없는데, 최근 갤럭시 노트20에서 앱을 실행하자마자 실행도 안되고 Crash난다는 리포트르를 받게 되었다.

 

해당 기기가 없어서 무슨 문제인지 도통 감을 못잡고 있던 찰나, 이용자 한 분께서 너무도 고맙게도 덤프 로그를 보내주셨다.

 

아래는 로그 내용.

02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: FATAL EXCEPTION: pool-10-thread-1
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: Process: ****, PID: 12466
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: java.lang.IllegalArgumentException: ****: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 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.
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:174)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
02-02 23:10:32.665 12316 12466 12561 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:920)

 

알고보니, AdMob 20.4.0의 릴리즈 노트에 있었던 것.

https://developers.google.com/admob/android/rel-notes

 

This release and all previous versions require an explicit dependency on androidx.work:work-runtime:2.7.0 to fix a bug causing app crashes on Android S with the following stack trace:

 
Fatal Exception: java.lang.IllegalArgumentException:
com.mycompany.myapp: Targeting S+ (version 10000 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:386)
   at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:657)
   at android.app.PendingIntent.getBroadcast(PendingIntent.java:644)
   at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:174)
   at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108)
   at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86)
   at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
   at java.lang.Thread.run(Thread.java:920)

To fix this bug, add the following dependencies for the Google Mobile Ads SDK to your module's app-level Gradle file:

 

build.gradle에 아래 constraints를 넣어주자.

dependencies {
  implementation 'com.google.android.gms:play-services-ads:20.4.0'

  // For apps targeting Android 12, add WorkManager dependency.
  constraints {
    implementation('androidx.work:work-runtime:2.7.0') {
      because '''androidx.work:work-runtime:2.1.0 pulled from
      play-services-ads has a bug using PendingIntent without
      FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps
      targeting S+.'''
    }
  }
}

 

이로써 해결 끝~!

 

다음 부터는 API레벨 별로, AVD 추가해서 테스트하는 습관을 들이는 것이 좋을 듯 하다.

반응형