[Android] IllegalArgumentException crash with 0.64-rc.2

Since upgrading to RN 0.64 we’re seeing the following crash on Android:

IllegalArgumentException
Unable to find JSIModule for class UIManager

java.lang.IllegalArgumentException: 
  at com.facebook.react.bridge.JSIModuleRegistry.getModule (JSIModuleRegistry.java:39)
  at com.facebook.react.bridge.CatalystInstanceImpl.getJSIModule (CatalystInstanceImpl.java:2)
  at com.facebook.react.uimanager.UIManagerHelper.getUIManager (UIManagerHelper.java:81)
  at com.facebook.react.uimanager.UIManagerHelper.getUIManager (UIManagerHelper.java:1)
  at com.facebook.react.uimanager.UIManagerHelper.getUIManagerForReactTag (UIManagerHelper.java:4)
  at com.facebook.react.animated.NativeAnimatedNodesManager.handleEvent (NativeAnimatedNodesManager.java:17)
  at com.facebook.react.animated.NativeAnimatedNodesManager.onEventDispatch (NativeAnimatedNodesManager.java:6)
  at com.facebook.react.uimanager.events.EventDispatcherImpl.dispatchEvent (EventDispatcherImpl.java:27)
  at com.facebook.react.uimanager.JSTouchDispatcher.handleTouchEvent (JSTouchDispatcher.java:58)
  at com.facebook.react.ReactRootView.dispatchJSTouchEvent (ReactRootView.java:49)
  at com.facebook.react.ReactRootView.onInterceptTouchEvent (ReactRootView.java)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2753)
  at com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView.dispatchTouchEvent (RNGestureHandlerEnabledRootView.java:12)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
  at com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:697)
  at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1879)
  at android.app.Activity.dispatchTouchEvent (Activity.java:3487)
  at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:2)
  at com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:655)
  at android.view.View.dispatchPointerEvent (View.java:13732)
  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:6131)
  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:5909)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5358)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5411)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5377)
  at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:5536)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5385)
  at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:5593)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5358)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5411)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5377)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5385)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5358)
  at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:8420)
  at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:8353)
  at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:8306)
  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:8535)
  at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:198)
  at android.os.MessageQueue.nativePollOnce (MessageQueue.java)
  at android.os.MessageQueue.next (MessageQueue.java:326)
  at android.os.Looper.loop (Looper.java:181)
  at android.app.ActivityThread.main (ActivityThread.java:7050)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)

I haven’t been able to reproduce the issue.
Could this be a compatibility issue with the new version of React Native?

  • React: 17.0.1
  • React Native: 0.64.rc.2
  • React Native Gesture Handler: 1.9.0

4 thoughts on “[Android] IllegalArgumentException crash with 0.64-rc.2

  1. I can’t see how this is a gesture handler problem. Looks like gesture handler is just tickling a react-native issue based on the stack. How is gesture handler responsible for react-native’s UIManagerHelper finding the JSIModule for it’s own UIManager? 🤔

  2. This link has video explanation of what UIManager is in React Native https://youtu.be/QwoQgzBgJu8?t=883

    RNGestureHandlerEnabledRootView inherits from ReactRootView

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mGestureRootHelper != null && mGestureRootHelper.dispatchTouchEvent(ev)) {
    return true;
    }
    return super.dispatchTouchEvent(ev);
    }

    The android ViewGroup calls onInterceptTouchEvent a method overridden by ReactRootView

    https://github.com/aosp-mirror/platform_frameworks_base/blob/1ac46f932ef88a8f96d652580d8105e361ffc842/core/java/android/view/ViewGroup.java#L2664

    intercepted = onInterceptTouchEvent(ev);

    https://github.com/facebook/react-native/blob/eacc94005b1b1d33d47b3bea88a6fd242560dafb/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java#L204-L207

      public boolean onInterceptTouchEvent(MotionEvent ev) {
        dispatchJSTouchEvent(ev);
        return super.onInterceptTouchEvent(ev);
      }

    The error is casued by the UIManager trying to dispatch this event to JavaScript via the bridge.
    The UIManager tries to retrieve the JavaScript Module responsible for handling this event, but no module is found and the consequent runtime is triggered.

    https://github.com/facebook/react-native/blob/eacc94005b1b1d33d47b3bea88a6fd242560dafb/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java#L64-L95

      /**
       * Main catalyst view is responsible for collecting and sending touch events to JS. This method
       * reacts for an incoming android native touch events ({@link MotionEvent}) and calls into {@link
       * com.facebook.react.uimanager.events.EventDispatcher} when appropriate. It uses {@link
       * com.facebook.react.uimanager.TouchTargetHelper#findTouchTargetView} helper method for figuring
       * out a react view ID in the case of ACTION_DOWN event (when the gesture starts).
       */
      public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
        int action = ev.getAction() & MotionEvent.ACTION_MASK;
        if (action == MotionEvent.ACTION_DOWN) {
          if (mTargetTag != -1) {
            FLog.e(
                ReactConstants.TAG, "Got DOWN touch before receiving UP or CANCEL from last gesture");
          }
    
    
          // First event for this gesture. We expect tag to be set to -1, and we use helper method
          // {@link #findTargetTagForTouch} to find react view ID that will be responsible for handling
          // this gesture
          mChildIsHandlingNativeGesture = false;
          mGestureStartTime = ev.getEventTime();
    
    
          mTargetTag = findTargetTagAndSetCoordinates(ev);
          eventDispatcher.dispatchEvent(
              TouchEvent.obtain(
                  getSurfaceId(),
                  mTargetTag,
                  TouchEventType.START,
                  ev,
                  mGestureStartTime,
                  mTargetCoordinates[0],
                  mTargetCoordinates[1],
                  mTouchEventCoalescingKeyHelper));
    /**
     * Class responsible for dispatching UI events to JS. The main purpose of this class is to act as an
     * intermediary between UI code generating events and JS, making sure we don't send more events than
     * JS can process.
     *
     * <p>To use it, create a subclass of {@link Event} and call {@link #dispatchEvent(Event)} whenever
     * there's a UI event to dispatch.
     *
     * <p>This class works by installing a Choreographer frame callback on the main thread. This
     * callback then enqueues a runnable on the JS thread (if one is not already pending) that is
     * responsible for actually dispatch events to JS. This implementation depends on the properties
     * that 1) FrameCallbacks run after UI events have been processed in Choreographer.java 2) when we
     * enqueue a runnable on the JS queue thread, it won't be called until after any previously enqueued
     * JS jobs have finished processing
     **/
      /** Sends the given Event to JS, coalescing eligible events if JS is backed up. */
      public void dispatchEvent(Event event) {
        Assertions.assertCondition(event.isInitialized(), "Dispatched event hasn't been initialized");
    
    
        for (EventDispatcherListener listener : mListeners) {
          listener.onEventDispatch(event);
        }
    
    
        synchronized (mEventsStagingLock) {
          mEventStaging.add(event);
          Systrace.startAsyncFlow(
              Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, event.getEventName(), event.getUniqueID());
        }
        maybePostFrameCallbackFromNonUI();
      }

    The JavaScript module is not found and triggers the above error

      public <T extends JavaScriptModule> T getJSModule(Class<T> jsInterface) {
        return mJSModuleRegistry.getJavaScriptModule(this, jsInterface);
      }

    would be interesting adding some debug statements in this react native source and see the different variables when using RNGestureHandlerEnabledRootView and normal React Native without Gesture Handler, to better understand the reason for this error. Thanks 🙏