React Native深度链接在Android 13中失效,跳转至首页问题排查
React Native Android 13深度链接跳转首页问题解决方案
针对你遇到的Android 13下深度链接跳首页、adb命令无法启动的问题,以下是具体修复步骤:
1. 修复adb命令的包名错误
你执行的adb命令中包名是br.com.soustixp,但错误提示显示系统尝试匹配br.com.soustix,包名不匹配导致无法启动Activity。使用正确包名重新执行:
adb shell am start -W -a android.intent.action.VIEW -d "https://campanha.soustix.com.br/redirect/p2p" br.com.soustix
2. 完善NavigationContainer的链接配置
你当前仅配置了prefixes,但未关联定义好的linkingConfig,导致React Navigation无法解析具体路径,默认跳转首页。修改App.tsx:
import { linkingConfig } from './src/config/deepLinkRoutes'; // ... 其他代码 <NavigationContainer linking={{ prefixes: ['https://campanha.soustix.com.br/redirect'], config: linkingConfig.config // 关联路径解析规则 }} >
3. 调整AndroidManifest的Intent Filter路径匹配
当前Intent Filter未指定pathPrefix,无法精准匹配带/redirect前缀的深度链接。修改data标签:
<data android:scheme="https" android:host="campanha.soustix.com.br" android:pathPrefix="/redirect"/>
不要写死/redirect/p2p,使用前缀可覆盖所有子路径的匹配需求。
4. 处理Android 13的SingleTask模式Intent传递
由于MainActivity使用singleTask启动模式,Android 13下App后台运行时,新Intent不会触发onCreate,需重写onNewIntent方法将Intent传递给React Navigation:
Java版本(MainActivity.java)
import android.content.Intent; import com.facebook.react.ReactActivity; import com.facebook.react.modules.linkinking.LinkingModule; public class MainActivity extends ReactActivity { // ... 原有代码 @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); if (getReactInstanceManager() != null && getReactInstanceManager().getCurrentReactContext() != null) { getReactInstanceManager().getCurrentReactContext() .getNativeModule(LinkingModule.class) .handleDeepLink(intent); } } }
Kotlin版本(MainActivity.kt)
import android.content.Intent import com.facebook.react.ReactActivity import com.facebook.react.modules.linkinking.LinkingModule class MainActivity : ReactActivity() { // ... 原有代码 override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) intent?.let { setIntent(it) reactInstanceManager.currentReactContext?.let { context -> context.getNativeModule(LinkingModule::class.java)?.handleDeepLink(it) } } } }
5. 验证Android App Links的AutoVerify配置
Android 13对App Links验证更严格,确保你的域名campanha.soustix.com.br已配置assetlinks.json文件,路径为https://campanha.soustix.com.br/.well-known/assetlinks.json,文件需包含应用包名和签名证书指纹。若验证失败,系统可能将链接交给浏览器处理,或导致App无法正确解析路径。
完成以上步骤后,重新打包安装应用,测试深度链接跳转即可。
内容的提问来源于stack exchange,提问作者João Raffo
相关产品推荐
相关产品推荐

