升级AGP与Gradle后DeepLink无法识别的问题求助
我的应用通过Navigation Component实现DeepLink功能,在AGP 8.0.2及Gradle Wrapper 8.0版本之前运行完全正常。仅升级这两个版本后,系统无法识别DeepLink,抛出错误:Activity not started, unable to resolve intent。
补充测试确认:仅升级AGP(即使升级至8.1.1版本)就会触发该问题。
现有配置
AndroidManifest.xml
<activity android:name=".delivery.DeliveryActivity" android:exported="true" android:launchMode="singleTask" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan" tools:ignore="LockedOrientationActivity"> <nav-graph android:value="@navigation/delivery_nav_graph" /> <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="myschemea://" android:host="myhost.com" android:pathPrefix="/receipt/delivery" /> </intent-filter> </activity>
导航图(delivery_nav_graph.xml)
<fragment android:id="@+id/delivery_payment_result" android:name="mypackage.delivery.payment.DeliveryPaymentResultFragment" android:label="@string/payment_result_title"> <deepLink android:autoVerify="false" app:mimeType="type/subtype" app:uri="myschema://myhost/receipt/delivery" /> </fragment>
排查与修复建议
- 修正Scheme拼写不一致问题:Manifest中配置的scheme是
myschemea://,但导航图DeepLink的uri写的是myschema://(少了一个字母a),AGP 8.0+对DeepLink的校验逻辑更严格,之前版本可能忽略了该错误,先统一两者的拼写。 - 移除不必要的MIME类型配置:如果你的DeepLink不需要指定MIME类型,直接删除
app:mimeType="type/subtype",避免额外的匹配限制。 - 检查AGP生成的最终Manifest:通过
Build > Analyze APK查看打包后的Manifest文件,确认<nav-graph>是否正确将导航图中的DeepLink合并到Activity的intent-filter中,排查是否存在配置丢失或冲突。 - 用ADB命令测试Intent有效性:执行以下命令直接测试DeepLink,验证是否能正常唤起Activity:
adb shell am start -a android.intent.action.VIEW -d "myschemea://myhost.com/receipt/delivery"
内容的提问来源于stack exchange,提问作者masztalski
相关产品推荐
相关产品推荐

