react native 0.49 android版本热更新

版本升级了,发现 老版本的 热更新 用不了,原来是 底层代码 改变了

 private void onJSBundleLoadedFromServer(File file) {
    if (file == null || !file.exists()) {
      Toast.makeText(this, "no file", Toast.LENGTH_SHORT).show();
      return;
    }
    // Toast.makeText(this, "Downloading complete", Toast.LENGTH_SHORT).show();
    try {
      //JSCConfig.EMPTY.getConfigMap();
      HybridData hb=new HybridData();
      ReactApplication application = (ReactApplication) this;
      Class<?> RIManagerClazz = application.getReactNativeHost().getReactInstanceManager().getClass();
      Method method = RIManagerClazz.getDeclaredMethod("recreateReactContextInBackground",
              JavaScriptExecutorFactory.class, JSBundleLoader.class);
      method.setAccessible(true);

      method.invoke(application.getReactNativeHost().getReactInstanceManager(),
              new JSCJavaScriptExecutorFactory(),
              JSBundleLoader.createFileLoader(file.getAbsolutePath()));
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

热更新 思路就是 把 index.android.bundle 下载下来 ,然后获取 路径,传入这个文件路径到这个函数里面,然后会 调用

recreateReactContextInBackground 这个方法 重新绑定 bundle 文件