API-33关于微信SDK无法正常登录的问题处理
问题概述
用户反馈某已上线新版本 app 更新后无法正常使用微信登录,可以正常跳转到微信中选择登录用户,但返回 app 后无响应。
已排查 AndroidManifest.xml 中关于包可见性设置配置正确:
<queries>
<package android:name="com.tencent.mm" />
</queries>
连接调试后发现微信 SDK 的 Log 日志报错:
E/MicroMsg.SDK.MMessageAct: sendUsingPendingIntent fail, ex = com.xxx.xxx: 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.
此问题搜索发现在微信开放社区也有人提问但尚未收到解决回复。
截止本文章发布,微信的最新版本 SDK 6.8.18 依然未解决此问题
大致可判断是因为高于 API-31 版本后,Google 强制限制了 PendingIntent 的 Flag 必须使用 FLAG_MUTABLE(可变) 或者 FLAG_IMMUTABLE(不可变),而微信 SDK 内部使用了禁止使用的其他 Flag 导致出现问题,但事实上在 app 的 targetSdkVersion 低于 33 时这个限制并非强制的,仅当 targetSdkVersion >= 33 时系统会强行判断禁止使用两者以外的值,而微信的 SDK 内部没有及时做出适配调整故而引发错误无法正确回调。
解决方法
微信已经更新开放平台中的文档:
根据最新文档,在manifest中,尝试去除WXEntryActivity的intent-filter。具体写法应该遵照上面接入方案中提到的示例,如下:
<activity
android:name=".wxapi.WXEntryActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:exported="true"
android:taskAffinity="填写你的包名"
android:launchMode="singleTask">
</activity>
——以下是原解决办法——
- 等待张小龙更新微信SDK(遥遥无期)
- 自行降级 app 的 targetSdkVersion 支持版本到 32 或更低。