如何从React Native Expo应用启动已安装的Unity构建Android应用?
解决从Expo应用启动Unity构建的Android应用的方法
方法1:通过Unity配置自定义Intent URI(推荐)
Unity打包Android时,可配置自定义Scheme让Expo通过URI启动应用:
- 打开Unity项目的
Player Settings(路径:Edit > Project Settings > Player) - 切换到Android平台,找到
Other Settings>Configuration>Intent Filter - 添加新的Intent Filter:
- 设置
Action为android.intent.action.VIEW - 设置
Category为android.intent.category.DEFAULT和android.intent.category.BROWSABLE - 设置
Data的Scheme为自定义值,比如myunitygame(可自行命名)
- 设置
- 重新打包Unity应用并安装到手机
在Expo应用中用expo-linking调用该URI:
import * as Linking from 'expo-linking'; const openUnityApp = async () => { const uri = 'myunitygame://'; // 对应Unity配置的Scheme const supported = await Linking.canOpenURL(uri); if (supported) { await Linking.openURL(uri); } else { console.log('无法打开Unity应用,请确认已安装'); } };
方法2:通过包名使用expo-intent-launcher启动
无需配置Scheme,直接通过Unity应用的包名启动,需确保主Activity允许外部调用:
- 获取Unity应用的包名:查看Unity
Player Settings里的Package Name(示例:com.myteam.unityapp) - 在Expo应用中调用
expo-intent-launcher的启动方法:
import * as IntentLauncher from 'expo-intent-launcher'; const openUnityApp = async () => { try { await IntentLauncher.startActivityAsync('android.intent.action.MAIN', { packageName: 'com.myteam.unityapp', // Unity应用的包名 className: 'com.unity3d.player.UnityPlayerActivity', // Unity默认主Activity类名 }); } catch (e) { console.log('启动失败:', e.message); } };
注意:若Unity自定义了主Activity,需替换为对应的类名;Unity 2021+版本默认主Activity已开启
android:exported="true",旧版本需手动在AndroidManifest.xml中添加该属性
常见问题排查
- Scheme启动失败:检查Unity的Intent Filter配置是否正确,重新打包安装
- 包名启动失败:确认Unity应用的包名、主Activity类名无误,且主Activity已设置
exported="true" - 测试注意:需使用Expo开发构建(
expo run:android)或打包后的APK,部分功能在Expo Go中无法正常使用
内容的提问来源于stack exchange,提问作者Ravindu Yasith
相关产品推荐
相关产品推荐

