赞
踩
本人之后又基于 Flutter SDK 1.12.13+hotfix.8 版本,做过一次动态更新。
Flutter 动态下发更新(Android 端)
热修复,目前只支持 Android 端的热修复。
纯Flutter代码,Google已经是支持热修复了,flutter.jar 里面也有相关的逻辑代码。利用的是微软的 CodePush。
Flutter 页面显示到 Android 端,实际就是用的 FlutterView 填充到 Activity或者 Fragment上的。
public static FlutterView createView(@NonNull final Activity activity, @NonNull final Lifecycle lifecycle, final String initialRoute) {
FlutterMain.startInitialization(activity.getApplicationContext());
FlutterMain.ensureInitializationComplete(activity.getApplicationContext(), null);
final FlutterNativeView nativeView = new FlutterNativeView(activity);
final FlutterView flutterView = new FlutterView(activity, null, nativeView);
......
return flutterView;
}
FlutterMain.startInitialization 主要做了初始化配置信息、初始化AOT编译和初始化资源,最后一部分则是加载Flutter的Native环境。跟热修复相关的主要是第三步,初始化资源 initResources()
public class FlutterMain { ...... private static final String SHARED_ASSET_DIR = "flutter_shared"; private static final String SHARED_ASSET_ICU_DATA = "icudtl.dat"; private static String sAotVmSnapshotData = "vm_snapshot_data"; private static String sAotVmSnapshotInstr = "vm_snapshot_instr"; private static String sAotIsolateSnapshotData = "isolate_snapshot_data"; private static String sAotIsolateSnapshotInstr = "isolate_snapshot_instr"; private static String sFlutterAssetsDir = "flutter_assets"; public static void startInitialization(Context applicationContext, FlutterMain.Settings settings) { ...... // 初始化配置信息 initConfig(applicationContext); // 初始化AOT编译 initAot(applicationContext); // 初始化资源 initResources(applicationContext); // 加载Flutter的Native环境 System.loadLibrary("flutter"); ...... } private static void initResources(Context applicationContext) { ...... sResourceExtractor = new ResourceExtractor(applicationContext); String icuAssetPath = "flutter_shared" + File.separator +
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。