Flutter Android 12:自定义Scheme致HTTPS深度链接默认禁用问题
Android 12 混合Scheme深度链接默认唤起异常解决方案
问题根源
Android 12(API 31+)对配置了android:autoVerify="true"的Intent Filter有严格校验规则:当同一个过滤器中同时包含自定义Scheme(如custom)和HTTP/HTTPS Scheme时,系统会判定该过滤器不符合自动验证条件,导致HTTPS链接的默认唤起权限无法自动生效,必须手动开启权限才能正常唤起应用。
修复方案
将原有的单个Intent Filter拆分为两个独立的过滤器,分别处理HTTP/HTTPS链接和自定义Scheme,确保HTTPS对应的过滤器满足autoVerify的校验要求:
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" /> <!-- 单独处理HTTP/HTTPS链接,保留autoVerify用于自动权限授予 --> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="my.domain.fr" /> <data android:scheme="https" /> <data android:scheme="http" /> </intent-filter> <!-- 单独处理自定义Scheme,无需autoVerify --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="custom" /> <!-- 若自定义Scheme需要绑定特定host,可添加android:host="my.domain.fr" --> </intent-filter>
方案说明
- 拆分过滤器:让HTTP/HTTPS链接的过滤器单独存在,满足
autoVerify的校验规则,系统会自动验证你的assetlinks.json配置,授予HTTPS链接的默认唤起权限。 - 自定义Scheme独立配置:自定义Scheme不属于Web链接范畴,无需添加
autoVerify,单独配置不会影响HTTPS链接的自动验证流程。
额外注意事项
- 确保
assetlinks.json正确部署在https://my.domain.fr/.well-known/assetlinks.json路径下,且Debug构建使用的SHA-256指纹与配置文件中的一致(Debug和Release版本指纹不同,需分别配置)。 - 测试HTTPS唤起可使用命令:
adb shell am start -a android.intent.action.VIEW -d "https://my.domain.fr"
内容的提问来源于stack exchange,提问作者Gautier Vuillaume
相关产品推荐
相关产品推荐

