如何解决Android API 31 - WorkManager - PendingIntent - 标记 IMMUTABLE 错误
例外: 定位 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一
导致异常的代码: WorkManager.getInstance(context).createCancelPendingIntent(id)
build.gradle 选项:
compileSdkVersion 31
buildToolsversion '30.0.3'(版本 31.0.0 给出错误:安装的构建工具修订版 31.0.0 已损坏。使用 SDK 管理器删除并重新安装)。
模拟器: API 31(使用 API S 一切正常)
依赖项:
// 工作管理器
实现“androidx.work:work-runtime-ktx:2.7.0-alpha05”
实现'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
我认为问题可能出在 BuildCompat.java 的这种方法中:
/**
* Checks if the device is running on a pre-release version of Android S or a release version of
* Android S or newer.
* <p>
* <strong>Note:</strong> When Android S is finalized for release,this method will be
* deprecated and all calls should be replaced with {@code Build.VERSION.SDK_INT >=
* Build.VERSION_CODES.S}.
*
* @return {@code true} if S APIs are available for use,{@code false} otherwise
*/
@ChecksSdkIntAtLeast(codename = "S")
public static boolean isAtLeastS() {
return VERSION.CODENAME.equals("S");
}
那是因为当我在模拟器上运行应用程序并记录版本名称时,我得到: 版本名称:REL
解决方法
基于 this bug,修复似乎是添加对 androidx.core:core:1.7.0-alpha01
的依赖,其中包括对 BuildCompat.isAtLeastS()
的修复。
看起来您缺少的是对最新版本的 android.core
的依赖。这包括对 BuildCompat.isAtLeastS()
进行重要错误修复的 this 更改。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。