Flutter Android本地测试Deep Link时ADB报错:无法解析Intent
测试Flutter Android Deep Link时的Intent解析错误
我在本地用ADB测试Android端Flutter Deep Link时碰到了错误,执行的ADB命令和报错信息如下:
adb shell 'am start -a android.intent.action.VIEW \ -c android.intent.category.BROWSABLE \ -d "http://courtyard.gg/"' \ gg.courtyard.courtyard_mobile Starting: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://courtyard.gg/... pkg=gg.courtyard.courtyard_mobile } Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://courtyard.gg/... flg=0x10000000 pkg=gg.courtyard.courtyard_mobile }
我已经按Flutter官方的Deep Link配置指南完成了设置,现在做本地测试。我的应用有三个不同的Flavor,对应不同的Dart入口,想问下是不是需要额外配置?下面是我的主Activity的AndroidManifest配置:
<application android:name="${applicationName}" android:icon="@mipmap/ic_launcher" android:label="@string/app_name"> <activity android:name=".MainActivity" android:allowBackup="true" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:exported="true" android:fullBackupContent="@xml/backup_rules" android:hardwareAccelerated="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:windowSoftInputMode="adjustResize"> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- Deep Linking --> <meta-data android:name="flutter_deeplinking_enabled" android:value="true" /> <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="courtyard.gg" android:scheme="http" /> <data android:scheme="https" /> </intent-filter> </activity> <meta-data android:name="flutterEmbedding" android:value="2" /> </application>
解决建议
- 核对Flavor对应的实际包名:ADB命令里指定的
gg.courtyard.courtyard_mobile可能和你当前安装的Flavor包名不匹配。用adb shell pm list packages | grep courtyard查看设备上已安装的该应用包名,确保命令中的包名和实际一致。 - 补充DEFAULT类别到ADB命令:隐式Intent启动Activity需要
DEFAULT类别,修改命令同时传入两个类别:adb shell 'am start -a android.intent.action.VIEW \ -c android.intent.category.DEFAULT \ -c android.intent.category.BROWSABLE \ -d "http://courtyard.gg/"' \ 你的实际包名 - 检查Flavor的Manifest合并结果:如果各Flavor有独立的AndroidManifest,要确认Deep Link的Intent Filter没有被覆盖。可以查看
app/build/intermediates/merged_manifests/下对应Flavor目录的合并后Manifest文件,验证Intent Filter是否存在。 - 先不指定包名测试匹配性:执行不带包名的命令,看系统是否能识别并弹出应用选择框:
若能弹出选择,说明Intent Filter配置正常,问题出在包名不匹配;若不能,再检查scheme、host是否和测试链接完全一致。adb shell 'am start -a android.intent.action.VIEW \ -c android.intent.category.DEFAULT \ -c android.intent.category.BROWSABLE \ -d "http://courtyard.gg/"'
内容的提问来源于stack exchange,提问作者FRANCISCO BERNAD
相关产品推荐
相关产品推荐

