在 Android 12 上崩溃,同时使用华为应用服务依赖项,使用构建工具 31

CRASH on Android 12 while using Huawei app service dependency, with build tools 31

我们实施了

"com.huawei.hms:appservice:$huaweiAppService" WHERE huaweiAppService = '6.1.0.301'

然后发生崩溃:

java.lang.IllegalArgumentException: 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.getActivityAsUser(PendingIntent.java:458)
    at android.app.PendingIntent.getActivity(PendingIntent.java:444)
    at android.app.PendingIntent.getActivity(PendingIntent.java:408)
    at com.huawei.hms.api.b.getErrPendingIntent(HuaweiApiAvailabilityImpl.java:10)
    at com.huawei.hms.common.internal.BaseHmsClient.resolution(BaseHmsClient.java:3)
    at com.huawei.hms.common.internal.BaseHmsClient.checkAvailabilityAndConnect(BaseHmsClient.java:34)
    at com.huawei.hms.common.internal.BaseHmsClient.connect(BaseHmsClient.java:1)
    at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.connect(HuaweiApiManager.java:21)
    at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.sendRequest(HuaweiApiManager.java:24)
    at com.huawei.hms.common.internal.HuaweiApiManager.connectAndSendRequest(HuaweiApiManager.java:8)
    at com.huawei.hms.common.internal.HuaweiApiManager.handleMessage(HuaweiApiManager.java:7)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.os.HandlerThread.run(HandlerThread.java:67)

我注意到一些华为服务已经有与问题相关的更新。所以我问的是应用服务。

感谢您的反馈,此问题是一个已知问题。研发团队将在11月中发布新的固定版本,我会更新这个答案,并在发布时通知您。

通过添加 huaweiBase transition dependency 和 appService dependency

暂时解决了问题。

它在后台更新了 appServiceLibrary 的一些源代码,看起来像是临时修复。在不久的将来,我将删除此基础依赖项并将 appService 更新为更新版本。

huaweiBase = '6.2.0.300'
huaweiAppService = '6.1.0.301'

huaweiDependencies = [
      huaweiBase: "com.huawei.hms:base:$huaweiBase",
      appService: "com.huawei.hms:appservice:$huaweiAppService"
]

    
implementation huaweiDependencies.huaweiBase
implementation huaweiDependencies.appService