You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从React Native Expo应用启动已安装的Unity构建Android应用?

解决从Expo应用启动Unity构建的Android应用的方法

方法1:通过Unity配置自定义Intent URI(推荐)

Unity打包Android时,可配置自定义Scheme让Expo通过URI启动应用:

  1. 打开Unity项目的Player Settings(路径:Edit > Project Settings > Player)
  2. 切换到Android平台,找到Other Settings > Configuration > Intent Filter
  3. 添加新的Intent Filter:
    • 设置Action为android.intent.action.VIEW
    • 设置Category为android.intent.category.DEFAULT和android.intent.category.BROWSABLE
    • 设置Data的Scheme为自定义值,比如myunitygame(可自行命名)
  4. 重新打包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允许外部调用:

  1. 获取Unity应用的包名:查看UnityPlayer Settings里的Package Name(示例:com.myteam.unityapp)
  2. 在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 16:53:13