Crash Unity Android 12 (API level 31): PendingIntent FLAG_IMMUTABLE or FLAG_MUTABLE

Lỗi crash game trên các máy nâng cấp lên Android 12:
Fatal Exception: java.lang.IllegalArgumentException
com.xxxx.xxxxx: 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.

Cách xử lý:
* Cách 1:
Chọn Target API level 30
* Cách 2:
1. In Unity, set the following checkbox to true to create a custom main gradle template file called mainTemplate.gradle: ProjectSettings>PlayerSettings>PublishingSettings>Build>Custom Main Gradle Template
2. In mainTemplate.gradle go to the dependencies section and change it to this:

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+.'''
}
}
}

About the Author: vietnamit

You May Also Like