This content originally appeared on DEV Community and was authored by ZHZL-m
1 -> Overview
DevEco Studio is a one-stop integrated development environment (IDE) for HarmonyOS application development based on the IntelliJ IDEA Community. Its cross-language code editing function provides developers with an efficient and convenient development experience in multi-language mixed programming scenarios, which greatly improves development efficiency.
1.1 -> Languages are supported in a variety of languages
DevEco Studio supports a variety of mainstream programming languages for HarmonyOS application development, including ArkTS, JS, C/C++, and more. Among them, ArkTS is the main application development language preferred by HarmonyOS, which expands on the TypeScript ecosystem and strengthens static inspection and analysis, making it suitable for efficient UI development. C++ is supported as an NDK toolset, which is suitable for performance-sensitive scenarios, reuse existing C or C++ libraries, and the development of special custom libraries for CPU characteristics, such as physics simulation, audio and video codec in game development, and other scenarios. In addition, Java, XML (Extensible Markup Language), JS (JavaScript), CSS (Cascading Style Sheets), and HML (HarmonyOS Markup Language) are also supported to meet the coding needs of different types of projects and business logic.
1.2 -> Cross-language code editing scenarios
Take advantage of different languages: When developing HarmonyOS applications, developers can use ArkTS or JS languages to take advantage of their convenience and efficiency in building interactive interfaces. For some core algorithms and low-level functional implementations that require extremely high performance, they can be written in C++ language. DevEco Studio’s cross-language code editing capabilities enable seamless collaboration between different language codes, making applications both user experience and high performance.
Reuse existing codebases: If there are a large number of existing C or C++ codebases in the project, or if you need to integrate third-party C++ libraries to implement specific functions, DevEco Studio’s cross-language capabilities can easily integrate these libraries with application logic developed based on ArkTS/JS, avoiding duplicate development and speeding up the project schedule.
2 -> Generate the glue code function framework
DevEco Studio provides cross-language code editing. When developers need to use NAPI to encapsulate the interface exposed to ArkTS/JS, in the Cpp header file, right-click Generate > NAPI to quickly generate the glue code function framework of the current function or class.
- Check whether napi_init.cpp files are included in the current CPP project entry > src > main > cpp path. If the file does not exist, place the cursor in the header file (supported types: .hpp, .hxx, .hh, .h) (currently supports bool, int, string, void, float, double, std::array, std::vector and other parameter types), right-click and select Generate > NAPI to generate the glue code framework file napi_ init.cpp。
- If a napi_init.cpp file already exists or has been created in the project, right-click and select Generate > NAPI in the name of the function/class to be called in the header file, and the corresponding function/class information will be registered in the napi_property_descriptor field of the napi_init.cpp file.
- In the TODO position of the napi_init.cpp file, add the corresponding function implementation code.
3 -> Quickly generate function definitions across languages
Currently, you can use the Generate native implementation function to generate the corresponding function definition in a C++ file in a cross-language d.ts file.
Hover the cursor over the undefined function name, click Generate native implementation in the overlay window, or click the red light bulb icon that appears on the page, and select Generate native implementation to generate the function definition.
This content originally appeared on DEV Community and was authored by ZHZL-m