LoginSignup
4
1

More than 1 year has passed since last update.

【Android】Android 12対応をする前にplay-services-analyticsのバージョンを確認しよう

Last updated at Posted at 2021-09-03

結論

v17.0.1以上に上げればOK

build.gradle
com.google.android.gms:play-services-analytics:17.0.1

The latest update to the Analytics library includes the following change:
・Fixed issue where library could not be built with Android 12 as its target.

何が修正されたのか(何が悪さをしていたのか)

初期化時に呼ばれるクラス内にAndroid12から必須となった可変性フラグが宣言されていないPendingIntentがあった

Application
GoogleAnalytics.getInstance(requireContext())
logcat
2021-07-27 22:57:39.172 15557-15697/hogehoge E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: hogehoge, PID: 15557
    java.lang.IllegalArgumentException: hogehoge: 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:375)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
        at com.google.android.gms.internal.gtm.zzbv.zzfe(Unknown Source:52)
        at com.google.android.gms.internal.gtm.zzbv.cancel(Unknown Source:54)
        at com.google.android.gms.internal.gtm.zzbv.zzaw(Unknown Source:4)
        at com.google.android.gms.internal.gtm.zzan.zzag(Unknown Source:7)
        at com.google.android.gms.internal.gtm.zzap.<init>(Unknown Source:67)
        at com.google.android.gms.internal.gtm.zzap.zzc(Unknown Source:82)
        at com.google.android.gms.analytics.GoogleAnalytics.getInstance(Unknown Source:15)
        ~~~~

可変性フラグとは

Android 12 をターゲットとするアプリでは、アプリが作成する個々の PendingIntent オブジェクトの可変性を指定する必要があります。この追加要件により、アプリのセキュリティが強化されます。
https://developer.android.com/about/versions/12/behavior-changes-12?hl=ja#pending-intent-mutability

v17.0.1未満では上記が原因でGA利用、(初期化の場所によるが)アプリがまともに起動できない状況に遭遇します。
Android12対応をしていく中で、自アプリ内のPendingIntentに可変性フラグを追加していくかと思いますが、それでもクラッシュが発生する際にはGA SDKのバージョンがv17.0.1未満になっていないか確認してみてください。

最後に

v17.0.1のアップデート自体、Android 12 Beta4が出たあとにリリースされており、なるべく早くAndroid12対応を進めていきたいアプリにとってはv17.0.1が出るまではGA SDKの削除を迫られるような状況となっていました。
今後のことを考えるとこれを機に推奨されているFirebase Analyticsへの移行を検討してみてもいいかも知れません。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1