Android编译SDK为31时调用SnapCreativeKitApi.send抛出IllegalArgumentException
问题背景
当Android项目使用31及以上版本编译SDK时,调用SnapCreativeKitApi.send方法会抛出IllegalArgumentException异常。目前Snapchat官方发布的最新SDK版本为v1.13.0,尚未修复该问题。
异常堆栈信息
IllegalArgumentException: com.test.test: 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.snapchat.kit.sdk.creative.api.SnapCreativeKitApi.sendWithCompletionHandler(SourceFile:151) at com.snapchat.kit.sdk.creative.api.SnapCreativeKitApi.send(SourceFile:100)
修复进度说明
目前Snapchat官方暂未对外公布该问题修复版本的具体发布时间。该问题属于Android 12版本适配的必填兼容性改动,优先级较高,大概率会在后续小版本更新中优先上线修复。
临时规避方案
- 临时将项目的compileSdk与targetSdk版本降级至30,可避开该PendingIntent检查逻辑,不影响相关接口正常调用
- 若业务必须使用31及以上版本编译,可通过反射修改SDK内部创建PendingIntent时传入的flag参数,在不需要PendingIntent可变的场景下优先添加
FLAG_IMMUTABLE标识 - 若业务依赖PendingIntent可变能力,添加
FLAG_MUTABLE标识即可正常运行
内容的提问来源于stack exchange,提问作者Shangeeth Sivan
相关产品推荐
相关产品推荐

