Добавить родной Android UnityPlayer в react-родное приложение, в результате чего черный экран

решен! Прочтите мой ответ.

Я пытаюсь отобразить представление Unity в собственном приложении React. Этот UnityPlayer показывает канал камеры для AR с Vuforia. Нам нужно включить это представление в приложение React-native для iOS и Android.

я следовал многим руководствам, но у меня есть черный экран в версии Android. Если я запускаю UnityPlayerActivity (из проекта Android, экспортированного Unity) в проекте Android, сгенерированном react-native (вместо ReactActivity), я правильно вижу свой UnityPlayer. Поэтому я думаю, что мой проект содержит все необходимые зависимости.

фрагмент кода моего кода js:

const UnityIosContainerView = requireNativeComponent("UnityContainerView",
null);
const UnityAndroidContainerView = requireNativeComponent("RCT3DView", null);

class ArPage extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, backgroundColor: "red" }}>
       {Platform.OS === "ios" ? (
         <UnityIosContainerView style={{ flex: 1 }} />
        ) : (
         <UnityAndroidContainerView style={{ flex: 1 }} />
        )}
      </View>
    );
  }
}

следуя этому руководству https://facebook.github.io/react-native/docs/native-components-android.html У меня есть пользовательский пакет

 public class CustomReactPackage implements ReactPackage {
  @Override
  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    return Collections.emptyList();
  }

  @Override
  public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
    return Arrays.<ViewManager>asList(
      new React3DViewManager()
    );
  }
}

и вот мой ViewManager подключен к жизни MainReactActivity для правильного управления UnityPlayer

public class React3DViewManager extends SimpleViewManager<View> implements LifecycleEventListener {

  public static final String REACT_CLASS = "RCT3DView";

  private UnityPlayer mUnityPlayer;

  @Override
  public String getName() {
    return REACT_CLASS;
  }

  @Override
  protected View createViewInstance(ThemedReactContext reactContext) {

    reactContext.addLifecycleEventListener(this);
    mUnityPlayer = new UnityPlayer(reactContext);
    int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
    boolean trueColor8888 = false;
    mUnityPlayer.init(glesMode, trueColor8888);
    mUnityPlayer.start();
    mUnityPlayer.requestFocus();

    return mUnityPlayer.getView();
  }

  @Override
  public void onHostResume() {
    mUnityPlayer.resume();
  }

  @Override
  public void onHostPause() {
   mUnityPlayer.pause();
  }

  @Override
  public void onHostDestroy() {
    mUnityPlayer.quit();
  }
}

в полученный скриншот:

enter image description here

проверенные точки:

  • показать родной ImageView работает.
  • показать простые работы GLSurfaceView.
  • попробуйте запустить UnityPlayerActivity вместо реактивности к valid, если все требования представлены в проекте Android. Все работает правильно.
  • попробуйте встроить UnityPlayer в пользовательский собственный вид не имеет никакого эффекта.
  • подключение UnityPlayer на время жизни действия (в ViewManager) не влияет, даже если вызываются события времени жизни.

Unity 2017.2.0f3

реагировать 16.0.0.0-alpha12

реагировать родной 0.48.4

кто-нибудь сталкивался с этой проблемой?

журнал приложений:

01-05 13:39:27.142 7233-7240/? I/art: Starting a blocking GC Instrumentation
01-05 13:39:27.156 7233-7233/? W/ActivityThread: Application com.protoreactnative is waiting for the debugger on port 8100...
01-05 13:39:27.156 7233-7233/? I/System.out: Sending WAIT chunk
01-05 13:39:29.228 7233-7240/com.protoreactnative I/art: Debugger is active
01-05 13:39:29.365 7233-7233/com.protoreactnative I/System.out: Debugger has connected
01-05 13:39:29.365 7233-7233/com.protoreactnative I/System.out: waiting for debugger to settle...
01-05 13:39:29.567 7233-7233/com.protoreactnative I/System.out: waiting for debugger to settle...
01-05 13:39:29.768 7233-7233/com.protoreactnative I/System.out: waiting for debugger to settle...
01-05 13:39:29.970 7233-7233/com.protoreactnative I/System.out: waiting for debugger to settle...
01-05 13:39:30.171 7233-7233/com.protoreactnative I/System.out: waiting for debugger to settle...
01-05 13:39:30.372 7233-7233/com.protoreactnative I/System.out: waiting for debugger to settle...
01-05 13:39:30.573 7233-7233/com.protoreactnative I/System.out: waiting for debugger to settle...
01-05 13:39:30.775 7233-7233/com.protoreactnative I/System.out: debugger has settled (1451)
01-05 13:39:31.131 7233-7233/com.protoreactnative I/InstantRun: starting instant run server: is main process
01-05 13:39:31.142 7233-7233/com.protoreactnative V/fb-UnpackingSoSource: locked dso store /data/user/0/com.protoreactnative/lib-main
01-05 13:39:31.143 7233-7233/com.protoreactnative I/fb-UnpackingSoSource: dso store is up-to-date: /data/user/0/com.protoreactnative/lib-main
01-05 13:39:31.143 7233-7233/com.protoreactnative V/fb-UnpackingSoSource: releasing dso store lock for /data/user/0/com.protoreactnative/lib-main
01-05 13:39:31.217 7233-7240/com.protoreactnative I/art: Starting a blocking GC Instrumentation
01-05 13:39:31.222 7233-7233/com.protoreactnative D/ReactNative: ReactInstanceManager.ctor()
01-05 13:39:31.272 7233-7233/com.protoreactnative D/NetworkSecurityConfig: No Network Security Config specified, using platform default
01-05 13:39:31.292 7233-7233/com.protoreactnative I/SensorManager: registerListenerImpl: listener = com.facebook.react.common.ShakeDetector@f6f1ff2, sensor = {Sensor name="Accelerometer Sensor", vendor="hTC Corp.", version=1, type=1, maxRange=39.2266, resolution=0.01, power=0.17, minDelay=10000}, delay = 66667, handler = null
01-05 13:39:31.315 7233-7233/com.protoreactnative D/ReactNative: ReactInstanceManager.createReactContextInBackground()
01-05 13:39:31.316 7233-7233/com.protoreactnative D/ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
01-05 13:39:31.318 7233-7233/com.protoreactnative D/ReactNative: ReactInstanceManager.onJSBundleLoadedFromServer()
01-05 13:39:31.321 7233-7233/com.protoreactnative D/ReactNative: ReactInstanceManager.recreateReactContextInBackground()
01-05 13:39:31.321 7233-7233/com.protoreactnative D/ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
01-05 13:39:31.359 7233-7254/com.protoreactnative I/art: Thread[15,tid=7254,Native,Thread*=0xf2e86b00,peer=0x12dcf280,"Thread-4"] recursive attempt to load library "/data/app/com.protoreactnative-2/lib/arm/libfb.so"
01-05 13:39:31.364 7233-7254/com.protoreactnative D/ReactNative: ReactInstanceManager.createReactContext()
01-05 13:39:31.394 7233-7233/com.protoreactnative W/unknown:ReactNative: Packager connection already open, nooping.
01-05 13:39:31.396 7233-7258/com.protoreactnative D/libc: [NET] android_getaddrinfofornetcontext+,hn 9(0x6c6f63616c686f),sn(),hints(known),family 0,flags 1024, proc=com.protoreactnative
01-05 13:39:31.396 7233-7255/com.protoreactnative D/libc: [NET] android_getaddrinfofornetcontext+,hn 9(0x6c6f63616c686f),sn(),hints(known),family 0,flags 1024, proc=com.protoreactnative
01-05 13:39:31.396 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfofornetcontext+,hn 9(0x6c6f63616c686f),sn(),hints(known),family 0,flags 1024, proc=com.protoreactnative
01-05 13:39:31.397 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy get netid:0
01-05 13:39:31.397 7233-7255/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy get netid:0
01-05 13:39:31.399 7233-7255/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy-, success
01-05 13:39:31.401 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy-, success
01-05 13:39:31.402 7233-7258/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy get netid:0
01-05 13:39:31.403 7233-7258/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy-, success
01-05 13:39:31.411 7233-7257/com.protoreactnative W/unknown:InspectorPackagerConnection: Couldn't connect to packager, will silently retry
01-05 13:39:31.457 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTGroupViewManager
01-05 13:39:31.467 7233-7262/com.protoreactnative I/Adreno: QUALCOMM build                   : b756f35, I9267f384df
                                                            Build Date                       : 10/19/16
                                                            OpenGL ES Shader Compiler Version: XE031.09.00.03
                                                            Local Branch                     : 
                                                            Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.BF64.1.2.3_RB1.07.00.00.258.005
                                                            Remote Branch                    : NONE
                                                            Reconstruct Branch               : NOTHING
01-05 13:39:31.467 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTGroupShadowNode
01-05 13:39:31.489 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTShapeViewManager
01-05 13:39:31.490 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTShapeShadowNode
01-05 13:39:31.503 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTTextViewManager
01-05 13:39:31.504 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTTextShadowNode
01-05 13:39:31.509 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.checkbox.ReactCheckBoxManager
01-05 13:39:31.540 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.uimanager.LayoutShadowNode
01-05 13:39:31.589 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.picker.ReactDialogPickerManager
01-05 13:39:31.600 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.drawer.ReactDrawerLayoutManager
01-05 13:39:31.608 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.picker.ReactDropdownPickerManager
01-05 13:39:31.612 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.scroll.ReactHorizontalScrollViewManager
01-05 13:39:31.631 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.scroll.ReactHorizontalScrollContainerViewManager
01-05 13:39:31.635 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.progressbar.ReactProgressBarViewManager
01-05 13:39:31.641 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.progressbar.ProgressBarShadowNode
01-05 13:39:31.646 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.scroll.ReactScrollViewManager
01-05 13:39:31.659 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.slider.ReactSliderManager
01-05 13:39:31.665 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.slider.ReactSliderManager$ReactSliderShadowNode
01-05 13:39:31.669 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.switchview.ReactSwitchManager
01-05 13:39:31.672 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.switchview.ReactSwitchManager$ReactSwitchShadowNode
01-05 13:39:31.676 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.toolbar.ReactToolbarManager
01-05 13:39:31.683 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.webview.ReactWebViewManager
01-05 13:39:31.692 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.swiperefresh.SwipeRefreshLayoutManager
01-05 13:39:31.697 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTSurfaceViewManager
01-05 13:39:31.699 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.art.ARTSurfaceViewShadowNode
01-05 13:39:31.704 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.frescosupport.FrescoBasedReactTextInlineImageViewManager
01-05 13:39:31.705 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.frescosupport.FrescoBasedReactTextInlineImageShadowNode
01-05 13:39:31.711 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.image.ReactImageManager
01-05 13:39:31.720 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.modal.ReactModalHostManager
01-05 13:39:31.723 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.modal.ModalHostShadowNode
01-05 13:39:31.725 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactRawTextManager
01-05 13:39:31.726 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactRawTextShadowNode
01-05 13:39:31.728 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.textinput.ReactTextInputManager
01-05 13:39:31.746 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.textinput.ReactTextInputShadowNode
01-05 13:39:31.757 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactTextViewManager
01-05 13:39:31.764 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactTextShadowNode
01-05 13:39:31.768 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.view.ReactViewManager
01-05 13:39:31.778 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.viewpager.ReactViewPagerManager
01-05 13:39:31.782 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactVirtualTextViewManager
01-05 13:39:31.783 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactVirtualTextShadowNode
01-05 13:39:31.785 7233-7254/com.protoreactnative W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.protoreactnative.react.React3DViewManager
01-05 13:39:31.844 7233-7254/com.protoreactnative D/ReactNative: Initializing React Xplat Bridge.
01-05 13:39:31.849 7233-7254/com.protoreactnative D/ReactNative: Initializing React Xplat Bridge before initializeBridge
01-05 13:39:31.863 7233-7254/com.protoreactnative D/ReactNative: Initializing React Xplat Bridge after initializeBridge
01-05 13:39:31.863 7233-7254/com.protoreactnative D/ReactNative: CatalystInstanceImpl.runJSBundle()
01-05 13:39:31.864 7233-7270/com.protoreactnative D/ReactNative: ReactInstanceManager.setupReactContext()
01-05 13:39:31.864 7233-7270/com.protoreactnative D/ReactNative: CatalystInstanceImpl.initialize()
01-05 13:39:31.866 7233-7270/com.protoreactnative W/unknown:ReactNative: Packager connection already open, nooping.
01-05 13:39:31.871 7233-7270/com.protoreactnative D/ReactNative: ReactInstanceManager.attachRootViewToInstance()
01-05 13:39:32.249 7233-7270/com.protoreactnative I/WebViewFactory: Loading com.android.chrome version 62.0.3202.84 (code 320208452)
01-05 13:39:32.293 7233-7270/com.protoreactnative I/cr_LibraryLoader: Time to load native libraries: 6 ms (timestamps 2695-2701)
01-05 13:39:32.311 7233-7270/com.protoreactnative I/chromium: [INFO:library_loader_hooks.cc(46)] Chromium logging enabled: level = 0, default verbosity = 0
01-05 13:39:32.313 7233-7270/com.protoreactnative I/cr_LibraryLoader: Expected native library version number "62.0.3202.84", actual native library version number "62.0.3202.84"
01-05 13:39:32.467 7233-7237/com.protoreactnative I/art: Do partial code cache collection, code=31KB, data=30KB
01-05 13:39:32.467 7233-7237/com.protoreactnative I/art: After code cache collection, code=30KB, data=29KB
01-05 13:39:32.467 7233-7237/com.protoreactnative I/art: Increasing code cache capacity to 128KB
01-05 13:39:32.692 7233-7269/com.protoreactnative I/ReactNativeJS: Running application "protoreactnative" with appParams: {"rootTag":1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
01-05 13:40:29.776 7233-7233/com.protoreactnative I/Unity: onResume
01-05 13:40:29.797 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfofornetcontext+,hn 9(0x6c6f63616c686f),sn(),hints(known),family 0,flags 1024, proc=com.protoreactnative
01-05 13:40:29.797 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy get netid:0
01-05 13:40:29.799 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy-, success
01-05 13:40:29.827 7233-7233/com.protoreactnative D/Unity: SetWindow 0 0xe3b38e08
01-05 13:40:29.827 7233-7233/com.protoreactnative D/Unity: SetWindow 0 0xe3b38e08
01-05 13:40:31.871 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfofornetcontext+,hn 9(0x6c6f63616c686f),sn(),hints(known),family 0,flags 1024, proc=com.protoreactnative
01-05 13:40:31.872 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy get netid:0
01-05 13:40:31.881 7233-7257/com.protoreactnative D/libc: [NET] android_getaddrinfo_proxy-, success

1 ответов


для получения дополнительной информации, все здесь описать : пройдите по ссылке

Ok после многих попыток я нашел решение. Очень важно подключить UnityPlayer ко всему сроку службы MainActivity. Класс ViewManager не поддерживает все время существования действия. Вы можете просто подключить менеджера, чтобы возобновить, приостановить и уничтожить. Но UnityPlayer требует onConfigurationChanged для обеспечения макет будет правильно. Я беру код непосредственно из класса UnityPlayerActivity генерируется Unity, и я выставляю UnityPlayer для использования в ViewManager.

вот моя основная активность с unityplayer init.

public class MainActivity extends ReactActivity {

  private UnityPlayer mUnityPlayer;

  public UnityPlayer getUnityPlayer() {
    return mUnityPlayer;
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy
    mUnityPlayer = new UnityPlayer(this);
  }

  public void onDestroy() {
    super.onDestroy();
    mUnityPlayer.quit();

  }

  public void onResume() {
    super.onResume();
    mUnityPlayer.resume();

  }

  /**
   * Returns the name of the main component registered from JavaScript.
   * This is used to schedule rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
        return "protoreactnative";
  }

  // Low Memory Unity
  @Override public void onLowMemory()
  {
    super.onLowMemory();
    mUnityPlayer.lowMemory();
  }

  // Trim Memory Unity
  @Override public void onTrimMemory(int level)
  {
    super.onTrimMemory(level);
    if (level == TRIM_MEMORY_RUNNING_CRITICAL)
    {
      mUnityPlayer.lowMemory();
    }
  }

  // This ensures the layout will be correct.
  @Override public void onConfigurationChanged(Configuration newConfig)
  {
    super.onConfigurationChanged(newConfig);
    mUnityPlayer.configurationChanged(newConfig);
  }

  // Notify Unity of the focus change.
  @Override public void onWindowFocusChanged(boolean hasFocus)
  {
    super.onWindowFocusChanged(hasFocus);
    mUnityPlayer.windowFocusChanged(hasFocus);
  }

  // For some reason the multiple keyevent type is not supported by the ndk.
  // Force event injection by overriding dispatchKeyEvent().
  @Override public boolean dispatchKeyEvent(KeyEvent event)
  {
    if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
      return mUnityPlayer.injectEvent(event);
    return super.dispatchKeyEvent(event);
  }

  // Pass any events not handled by (unfocused) views straight to UnityPlayer
  @Override public boolean onKeyUp(int keyCode, KeyEvent event)     { return mUnityPlayer.injectEvent(event); }
  @Override public boolean onKeyDown(int keyCode, KeyEvent event)   { return mUnityPlayer.injectEvent(event); }
  @Override public boolean onTouchEvent(MotionEvent event)          { return mUnityPlayer.injectEvent(event); }
  /*API12*/ public boolean onGenericMotionEvent(MotionEvent event)  { return mUnityPlayer.injectEvent(event); }
}

вот менеджер вид :

public class React3DViewManager extends SimpleViewManager<UnityPlayer>  {

  public static final String REACT_CLASS = "RCT3DView";

  @Override
  public String getName() {
    return REACT_CLASS;
  }

  @Override
  protected UnityPlayer createViewInstance(ThemedReactContext reactContext) {
    MainActivity activity = (MainActivity)reactContext.getCurrentActivity();
    return activity.getUnityPlayer();
  }
}

Я не знаю, является ли это решение лучшим решением, но это решение работает правильно для моих нужд.

спасибо