Flutter Android 混合开发的依赖关系。

FlutterApplication

进入 FlutterMain.startInitialization(this);

FlutterMain片段

进入initConfig(applicationContext);

FlutterMain片段
FlutterMain片段
flutter编译产物

app怎么依赖assets目录下的这些东西呢?

进入initAot(applicationContext);

读取assets文件


FlutterMain片段

存放的位置
进入initResources(applicationContext);

private static void initResources(Context applicationContext) {
        Context context = applicationContext;
        (new ResourceCleaner(applicationContext)).start();
        Bundle metaData = null;

        try {
            metaData = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128).metaData;
        } catch (NameNotFoundException var4) {
            Log.e("FlutterMain", "Unable to read application info", var4);
        }

        if (metaData != null && metaData.getBoolean("DynamicPatching")) {
            sResourceUpdater = new ResourceUpdater(applicationContext);
            if (sResourceUpdater.getDownloadMode() == DownloadMode.ON_RESTART || sResourceUpdater.getDownloadMode() == DownloadMode.ON_RESUME) {
                sResourceUpdater.startUpdateDownloadOnce();
                if (sResourceUpdater.getInstallMode() == InstallMode.IMMEDIATE) {
                    sResourceUpdater.waitForDownloadCompletion();
                }
            }
        }

        sResourceExtractor = new ResourceExtractor(applicationContext);
        sResourceExtractor.addResource(fromFlutterAssets(sFlx)).addResource(fromFlutterAssets(sAotVmSnapshotData)).addResource(fromFlutterAssets(sAotVmSnapshotInstr)).addResource(fromFlutterAssets(sAotIsolateSnapshotData)).addResource(fromFlutterAssets(sAotIsolateSnapshotInstr)).addResource(fromFlutterAssets("kernel_blob.bin"));
        if (sIsPrecompiledAsSharedLibrary) {
            sResourceExtractor.addResource(sAotSharedLibraryPath);
        } else {
            sResourceExtractor.addResource(sAotVmSnapshotData).addResource(sAotVmSnapshotInstr).addResource(sAotIsolateSnapshotData).addResource(sAotIsolateSnapshotInstr);
        }

        sResourceExtractor.start();
    }

FlutterActivity与FlutterActivityDelegate


FlutterActivity片段
FlutterActivity片段
FlutterActivityDelegate的onCreate()

ensureInitializationComplete是把flutter相关的初始化进来然后使用FlutterView进行行加载显示

找到flutter_assets下的flutter产物

每一个FlutterView中包了一个FlutterNativeView然后最终就是FlutterView->runFromBundle调用FlutterNativeView->runFromBundle最后渲染到界面上

来自闲鱼

app module


这三个不用copy,app依赖my_flutter module就可以
复制这个到app module 对应目录实现手动热更新

依赖完成就可以通过startActivity成功的进入到FlutterActivity

https://zhuanlan.zhihu.com/p/40528502
https://yq.aliyun.com/articles/607014

你可能感兴趣的:(Flutter Android 混合开发的依赖关系。)