作者:无与伦比的美丽MJ | 来源:互联网 | 2023-05-19 04:55
版本升级了,发现老版本的热更新用不了,原来是底层代码改变了privatevoidonJSBundleLoadedFromServer(Filefile){if
版本升级了,发现 老版本的 热更新 用不了,原来是 底层代码 改变了
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 文件