当应用程序在 Android 12 API 32 上使用 Retrofit 进行 API 调用时崩溃

App crash when It makes API call using Retrofit on Android 12 API 32

谁能帮帮我。我已经为支持 Android 12 的所有未决意图添加了 FLAG_IMMUTABLE 标志,但是当尝试在应用程序启动时使用改造调用任何 API 时,应用程序会抛出异常并崩溃。

Http 日志

I/okhttp.OkHttpClient: --> GET https://api.covantex.com/v1/EnvironmentFlags
I/okhttp.OkHttpClient: --> END GET
I/okhttp.OkHttpClient: <-- HTTP FAILED: java.lang.IllegalArgumentException: com.covantex: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
I/okhttp.OkHttpClient: 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.
I/okhttp.OkHttpClient: <-- HTTP FAILED: java.lang.IllegalArgumentException: com.covantex: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
I/okhttp.OkHttpClient: 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.

使用 APIs

的库
implementation "com.google.code.gson:gson:2.9.0"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.2"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation "com.squareup.retrofit2:converter-scalars:2.9.0"

这样试试:PendingIntent clickPendingIntent = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);