Android Deep Linking失效:assetlinks.json配置后网页链接无法唤起App
Android 深度链接网站链接无法唤起应用问题排查
问题背景
配置自定义Scheme(mygainplan://)可正常唤起应用,但HTTPS网站链接(https://www.my-gainplan.com/workouts)仅打开浏览器,无法唤起应用。相关配置如下:
AndroidManifest.xml 配置
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.VIBRATE" /> <application android:usesCleartextTraffic="true" android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme" android:screenOrientation="portrait"> <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true"> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <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="mygainplan" /> </intent-filter> <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="http" /> <data android:scheme="https" /> <data android:host="www.my-gainplan.com" /> <data android:pathPrefix="/workouts" /> </intent-filter> </activity> </application> </manifest>
React Navigation 链接配置
const linking = { prefixes: [ 'https://www.my-gainplan.com', 'mygainplan://', 'https://my-gainplan.com', ], config: { screens: { MyWorkouts: 'workouts', }, }, };
Asset Links 配置
[ { "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.mygainplan", "sha256_cert_fingerprints": [ "FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C" ] } } ]
核心原因与解决步骤
1. Intent-Filter 缺失 autoVerify 属性
App Links(HTTPS深度链接)要求对应的intent-filter必须添加android:autoVerify="true",否则系统不会自动验证assetlinks.json,也不会将域名与应用绑定。
修改方案:给HTTPS对应的intent-filter添加该属性:
<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:scheme="http" /> <data android:scheme="https" /> <data android:host="www.my-gainplan.com" /> <data android:pathPrefix="/workouts" /> </intent-filter>
2. 验证 assetlinks.json 的可访问性
- 确保文件放在网站根目录的
.well-known子目录下,即必须能通过https://www.my-gainplan.com/.well-known/assetlinks.json直接访问 - 检查文件内容无语法错误,与配置完全一致
- 确保网站使用可信SSL证书(自签证书在调试环境可能无法通过验证)
3. 确认SHA256指纹正确性
调试环境的SHA256必须来自调试密钥库,可通过以下命令重新获取:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
将输出的SHA256指纹与assetlinks.json中的值对比,确保大小写、冒号完全一致。
4. 强制触发系统验证
卸载应用后重新安装,系统会在安装时自动验证assetlinks.json。也可通过ADB命令直接测试链接唤起:
adb shell am start -a android.intent.action.VIEW -d "https://www.my-gainplan.com/workouts"
5. 检查域名覆盖范围
React Navigation的prefixes包含https://my-gainplan.com(不带www),但Manifest中仅配置了www.my-gainplan.com。如果需要支持不带www的域名,需在Manifest中添加对应的data android:host="my-gainplan.com"配置。
内容的提问来源于stack exchange,提问作者JaRoMaster
相关产品推荐
相关产品推荐

