How JD Finance Tackles HarmonyOS: A Dynamic Cross-Platform Adaptation Blueprint
JD Finance’s engineering team outlines a dynamic, cross-platform adaptation strategy for migrating Android apps to the new HarmonyOS, detailing challenges of native rewrites, the V8 virtual machine port, JSI communication layers, layout integration with Yoga, and future plans for self-drawn rendering and mini-program conversion.
1. Background
Huawei announced at the 2023‑09‑25 official launch that the new HarmonyOS will no longer be compatible with Android applications, meaning that all Android apps, including JD Finance, cannot run on the new system and must be redeveloped as dedicated HarmonyOS apps.
2. Native Adaptation Plan
The native adaptation approach would rewrite all business and infrastructure layers of the JD Finance app using HarmonyOS language, but it faces three major problems:
High initial development cost : 1:1 development of a HarmonyOS version requires a long development cycle and huge R&D investment.
High business iteration cost : Future updates must be performed simultaneously on iOS, Android, HarmonyOS and other platforms, increasing product communication, development, testing and UI acceptance costs.
Low release efficiency : After a business requirement is completed, the app must be submitted, reviewed and published on the Huawei AppGallery, resulting in a long release cycle and no ability for on-demand publishing.
3. Dynamic Adaptation Plan
“Dynamic” is a self-developed solution by JD Finance’s front-end team that enables a single codebase to run on iOS, Android and Web.
1. Plan Overview
The dynamic solution already supports one code running on iOS, Android and H5. By integrating this capability with HarmonyOS, the initial adaptation effort is reduced, allowing one-time development for four platforms and long-term reduction of business iteration costs, while also providing instant publishing capability.
2. Implementation
The implementation on HarmonyOS follows a process similar to Android but faces challenges such as the lack of a V8 virtual machine, complex core-layer communication, and the need to port the layout library.
Key steps include:
Virtual Machine Layer – V8
HarmonyOS does not provide a JSCore or V8 VM, so V8 must be ported (V8 For Harmony).
Virtual Machine Interface Layer
After porting V8, ArkTS is used to wrap and invoke V8 interfaces (ArkTs2V8).
Dynamic Engine Runtime
Running the RomaEngine JavaScript file generates a virtual DOM (V‑Dom) tree and performs diffing to trigger UI updates.
Communication Layer – JSI
RomaEngine’s V‑Dom creation triggers native rendering node creation. On iOS and Android this communication uses JSON, which has performance limits; on HarmonyOS we adopt the industry-standard JSI to establish JS ↔ C++ communication.
Native SDK Layer
JSI enables C++ to receive node-creation commands from JS. Since HarmonyOS native UI uses ArkTS, we use the NAPI interface to bridge C++ and ArkTS, achieving a JS → C++ → ArkTS communication chain (and the reverse).
Layout Layer
Yoga, a cross-platform layout engine, has been ported to HarmonyOS to compute final positions and sizes of UI elements, completing the rendering pipeline.
Interaction Handling
For example, a button click is propagated through ArkTS → C++ → JS to deliver the event to the business logic.
3. Key Technologies
V8 Virtual Machine Porting
Self‑compiled V8 cross‑compilation required mastering CMake, Clang, LLVM, Ninja, etc. The team has mastered V8 cross-compilation and porting techniques.
Huawei’s built-in V8 solution offers long-term benefits in package size, stability, compatibility and maintenance cost.
Communication Scheme Design
HarmonyOS provides NAPI for ArkTS ↔ C/C++ communication. The dynamic solution’s JSI establishes JS ↔ C++ communication, enabling three‑language interaction (JS, C++, ArkTS).
Page Rendering Scheme
RomaEngine produces a V‑Dom tree; through JSI, component creation commands are sent to build a ComponentTree that mirrors the V‑Dom. The ComponentTree is then mapped to a RenderTree using HarmonyOS custom components.
On subsequent updates, a new V‑Dom is diffed against the old one, and only changed nodes are sent via JSI to update the RenderTree.
Layout Scheme
Yoga has been compiled for HarmonyOS, ensuring consistent layout calculations across iOS, Android and HarmonyOS.
4. Future Plans
Self‑Draw Solution
With emerging OSes such as Xiaomi’s Pengpai OS and Vivo’s blueOS, the team plans to explore SKIA‑based self‑draw rendering to achieve a single rendering codebase across iOS, Android, HarmonyOS, Pengpai OS, blueOS and future systems.
Mini‑Program Conversion
The V‑Dom architecture can also generate code for WeChat, Douyin, Baidu and other mini‑programs, enabling low‑cost private‑domain deployment.
Ecosystem Expansion
Future devices will form an Internet‑of‑Things world; the dynamic solution will continue to explore techniques for running on more devices, such as seamless flow between smartphones and car systems.
JD Cloud Developers
JD Cloud Developers (Developer of JD Technology) is a JD Technology Group platform offering technical sharing and communication for AI, cloud computing, IoT and related developers. It publishes JD product technical information, industry content, and tech event news. Embrace technology and partner with developers to envision the future.
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.