Flutter‑Based Cross‑Platform Development and Dynamic Update Solutions at JD Daojia
This article details JD Daojia's mobile‑side engineering practices, covering a unified Flutter SDK, resource management, state‑management patterns, precise exposure tracking, and a custom dynamic‑update mechanism that enables hot‑swapping of Flutter binaries and assets on Android.
In recent years, the rapid spread of smart mobile devices has made multi‑platform unified development frameworks a hot topic. JD Daojia's mobile team has explored cross‑platform solutions using RN, Taro, and Flutter, and since late 2019 has built a comprehensive Flutter‑based dual‑platform integration covering SDK output, unified resource management, state‑management mechanisms, precise exposure tracking, and CI‑driven dynamic capabilities.
SDK Common Solution
The team created a base Flutter container that provides core service components and a fast‑track integration ability for third‑party modules, together with mature CI pipelines and downgrade strategies, significantly lowering the entry barrier and improving development efficiency.
Resource Manager and Third‑Party Fast Integration
Each Flutter module is packaged as an independent Plugin, requiring unified resource referencing and route registration. An automatically generated R.dart file mimics Android's R class, mapping assets via a build‑time generator that scans pubspec.yaml and creates Dart resource classes.
class ResGenerator extends GeneratorForAnnotation<ResPath> {
@override
generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) {
// 1. Load pubspec.yaml
var package = loadYaml(new File('pubspec.yaml')?.readAsStringSync());
// 2. Scan default asset paths
var defaultPath = pubspecModel?.flutter?.assets;
// 3. Process each file
for (String pathStr in pathList) {
handleFile(pathStr);
}
// 4. Handle fonts
List<Fonts> fonts = pubspecModel?.flutter?.fonts;
// 5. Generate Dart file
return // template code
}
}Running flutter packages pub run build_runner build produces an R.dart with static references to packages, images, and other assets.
Flutter State Management
Traditional setState approaches cause whole‑tree rebuilds or require expensive GlobalKey usage. JD Daojia adopts Provider‑based state management where each refreshable node is a DJBaseProvideNode that notifies listeners via notifyListeners() , enabling fine‑grained updates without memory overhead.
@override Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("标题栏")),
body: DJBaseProvideNode(
baseProvider,
children: [
StoreListWidget(onItemClick: () { baseProvider.clickStore(); }),
DJBaseProvideNode<CateProvider>(cateProvider, CateListWidget),
DJBaseProvideNode<GoodProvider>(goodProvider, GoodListWidget)
]
)
);
}Precise Exposure Tracking
The solution defines exposure rules (first appearance, data refresh, re‑entry after scroll out) and computes visible height for both regular and Sliver lists using RenderObject metrics, ensuring accurate reporting for nested and multi‑row lists.
Flutter Dynamic Update Mechanism
Because Flutter does not natively support hot updates, JD Daojia replaces libapp.so and the flutter_assets directory at runtime. By injecting a custom library path into FlutterMain.ensureInitializationComplete() and adding a DirectoryAssetBundle to the engine's AssetManager , both code and resources can be loaded from external storage.
// Add custom libapp.so path
shellArgs.add("--" + AOT_SHARED_LIBRARY_NAME + "=" + customLibPath);
FlutterJNI.nativeInit(...);
// Push custom asset bundle
asset_manager->PushFront(std::make_unique<DirectoryAssetBundle>(fml::OpenDirectory(customAssetPath)));Incremental Patch Distribution
Full Flutter bundles exceed 5 MB, so JD Daojia uses bsdiff‑based differential patches (via Tinker) to deliver incremental updates, reducing download size and improving reliability.
Patch Management Platform
A front‑end patch management system handles versioning, fingerprint and signature verification, downgrade/gray‑release strategies, and supports multiple Flutter SDK and channel versions to ensure safe A/B testing without requiring a full app release.
Overall, the article presents a complete end‑to‑end workflow for building, managing, and dynamically updating Flutter modules in a large‑scale Android application.
Dada Group Technology
Sharing insights and experiences from Dada Group's R&D department on product refinement and technology advancement, connecting with fellow geeks to exchange ideas and grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.