Android DeepLink配置报错求助:资源未找到及正确配置方法
Hey,我看了你的问题和代码,现在有两个关键问题导致你的DeepLink配置失败,我一步步帮你搞定:
1. 先解决编译报错的字符串资源问题
从日志里的No resource found that matches the given name可以看出,你在Manifest里引用了@string/title_gizmos、@string/filter_view_http_gizmos这些字符串资源,但你的项目里根本没定义它们。你有两个简单的解决办法:
- 快速方案:直接把这些引用换成硬编码的字符串,比如把
android:label="@string/title_gizmos"改成android:label="Gizmos",android:label="@string/filter_view_http_gizmos"改成android:label="Open via HTTP Link" - 规范方案:如果想保持资源引用的方式,你需要在项目的
res/values/strings.xml文件里添加对应的字符串定义(如果是Kodular项目,可以用APK编辑器的资源编辑功能找到这个文件添加)
2. 修复Manifest里的语法错误
看你的Manifest代码,Screen1这个Activity标签里多了一行完全无效的代码:
android:name="com.example.android.GizmosActivity"
这行代码直接放在</intent-filter>后面,不属于任何XML标签,会直接导致XML解析失败,必须删掉这行。
3. 适配Kodular项目的正确DeepLink配置
你之前新增了一个com.example.android.GizmosActivity的Activity,但这个是官方教程里的示例类,你的Kodular项目里根本没有这个Activity,所以完全没必要加它。正确的做法是把DeepLink的Intent Filter直接加到你的主Activity(也就是Screen1)上,这样点击链接时才能直接唤起你的APP主页面。
下面是修改后的完整Manifest代码,已经帮你修正了所有问题:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="28" android:compileSdkVersionCodename="9" android:installLocation="auto" package="io.kodular.ontstudios.Deeplinks_Test" platformBuildVersionCode="28" platformBuildVersionName="9"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <application android:debuggable="false" android:icon="@mipmap/ic_launcher" android:label="Deeplinks_Test" android:name="com.google.appinventor.components.runtime.multidex.MultiDexApplication" android:networkSecurityConfig="@xml/network_security_config" android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="false" android:theme="@style/AppTheme" android:usesCleartextTraffic="true"> <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize" android:name="io.kodular.ontstudios.Deeplinks_Test.Screen1" android:theme="@style/AppTheme.NoActionBar" android:windowSoftInputMode="stateHidden"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <!-- HTTP协议的DeepLink规则 --> <intent-filter android:label="Open Gizmos via HTTP"> <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" android:host="www.example.com" android:pathPrefix="/gizmos" /> </intent-filter> <!-- 自定义Scheme的DeepLink规则 --> <intent-filter android:label="Open Gizmos via Custom Scheme"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="example" android:host="gizmos" /> </intent-filter> </activity> <meta-data android:name="io.kodular.app.VERSION" android:value="1.4C.4-Eagle"/> <provider android:authorities="io.kodular.ontstudios.Deeplinks_Test.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider> <uses-library android:name="org.apache.http.legacy" android:required="false"/> <meta-data android:name="Kodular_RCWTFYP-BYDNKHMWRIT-DNLATT" android:value="_d4705d7c44acc5bd4f7b41c83f38a3b7.d4705d7c44acc5bd4f7b41c83f38a3b7-1591708822~IHyiEtMYRvDgxXbt4rhOSnOCkopeFofjrENFozlMYAzosQQBVH5WqkA1OStZfxta_"/> </application> </manifest>
4. 测试DeepLink是否生效
修复后重新编译APK并安装,你可以用ADB命令快速测试:
- 测试HTTP链接:
adb shell am start -a android.intent.action.VIEW -d "http://www.example.com/gizmos"
- 测试自定义Scheme链接:
adb shell am start -a android.intent.action.VIEW -d "example://gizmos"
如果后续要用到自己的域名,记得把www.example.com改成你实际的域名,同时如果要配置App Links(直接打开APP而不是选择器),还需要在域名根目录配置assetlinks.json文件,不过先确保基础的DeepLink能正常唤起APP再说~
内容的提问来源于stack exchange,提问作者ONT Studios

