android - 在 react-native 应用程序中添加 Native Android UnityPlayer 导致黑屏

标签 android unity3d react-native native

已解决!阅读我的回答。

我正在尝试在 native React 应用程序中显示 Unity View 。此 UnityPlayer 使用 Vuforia 显示 AR 的相机源。我们需要将此 View 包含在适用于 iOS 和 Android 的 React-native 应用程序中。

我遵循了很多指南,但在 Android 版本中出现黑屏。 如果我在 react-native(而不是 ReactActivity)生成的 Android 项目中运行 UnityPlayerActivity(从 Unity 导出的 Android 项目),我会正确地看到我的 UnityPlayer。所以我想我的项目包含所有必要的依赖项。

我的 js 代码 fragment :

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 作品。
  • 如果 Android 项目中存在所有要求,请尝试启动 UnityPlayerActivity 而不是 ReactActivity 以验证。一切正常。
  • 尝试在自定义原生 View 中嵌入 UnityPlayer 没有效果。
  • 将 UnityPlayer 连接到 Activity 生命周期(在 ViewManager 中)没有任何效果,即使生命周期事件被调用也是如此。

统一 2017.2.0f3

react 16.0.0.0-alpha12

React-native 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

最佳答案

有关更多信息,请在此处进行描述: Part 1 Part 2

好的,经过多次尝试,我找到了解决方案。 将 UnityPlayer 连接到 MainActivity 的所有 Lifetime 非常重要。 ViewManager 类不支持所有 Activity 生命周期。您只需连接管理器即可恢复、暂停和销毁。但是 UnityPlayer 需要 onConfigurationChanged 来确保布局正确。我直接从 Unity 生成的类 UnityPlayerActivity 中获取代码,并在 ViewManager 中公开 UnityPlayer 以供使用。

这是我的 MainActivity 和 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); }
}

这是 View 管理器:

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();
  }
}

我不知道这个解决方案是否是最好的解决方案,但这个解决方案可以很好地满足我的需求。

谢谢

关于android - 在 react-native 应用程序中添加 Native Android UnityPlayer 导致黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48116993/

相关文章:

javascript - 从数组中删除项目(useState Hook)

javascript - 使用从 Alphavantage 返回的 axios 对象更新 ReactJS 状态

java - 在 Android 上请求发帖时出现问题

android - React Native - "Absolute"位置和 "zIndex"在 Android 上不起作用

android - ADT18、App Engine 连接的 Android 项目和 noclassdeffounderror

c# - 统一评分系统的创建

android - 找不到 google-play-services_lib

android - Facebook 登录在 android 的 react-native 应用程序中

c# - Unity构建和运行游戏错误: Error building Player: Extracting referenced dlls failed

javascript - React Native/Javascript 中两个数组的合并