React-Native-Remote-Update icon indicating copy to clipboard operation
React-Native-Remote-Update copied to clipboard

在0.17版本上,热更新报错

Open hongjie104 opened this issue 9 years ago • 0 comments

 method.invoke(mReactInstanceManager,
    new JSCJavaScriptExecutor(),
    JSBundleLoader.createFileLoader(context, mainBundleFilePath));

在执行这一句时,抛出了一个IllegalAccessException异常,通过log可知是在ReactInstanceManagerImpl类中的下面这个方法中执行了UiThreadUtil.assertOnUiThread(); 该方法判断当前不在UI线程,于是抛出异常说“Expected to run on UI thread!”

private void recreateReactContextInBackgroundInner() {
    UiThreadUtil.assertOnUiThread();

    if (mUseDeveloperSupport && mJSMainModuleName != null) {
      if (mDevSupportManager.hasUpToDateJSBundleInCache()) {
        // If there is a up-to-date bundle downloaded from server, always use that
        onJSBundleLoadedFromServer();
      } else if (mJSBundleFile == null) {
        mDevSupportManager.handleReloadJS();
      } else {
        mDevSupportManager.isPackagerRunning(
            new DevServerHelper.PackagerStatusCallback() {
              @Override
              public void onPackagerStatusFetched(final boolean packagerIsRunning) {
                UiThreadUtil.runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (packagerIsRunning) {
                          mDevSupportManager.handleReloadJS();
                        } else {
                          recreateReactContextInBackgroundFromBundleFile();
                        }
                      }
                    });
              }
            });
      }
      return;
    }

    recreateReactContextInBackgroundFromBundleFile();
  }

那么。。。如果运行在UI线程里呢?

hongjie104 avatar Jan 13 '16 09:01 hongjie104