Since version 26.0.1, DevEco Studio supports batch import and batch removal of .so libraries built based on CMake projects. If the current project references .so libraries built by other project modules, after importing these .so libraries in batches in the current project, you can directly view the source code of the libraries for code reading, breakpoint debugging, issue locating, and other capabilities. This avoids frequent switching between multiple projects and improves development efficiency.
When you import .so libraries from other project modules, DevEco Studio associates the source code of the .so libraries with the current project based on the build information of the CMake project of these libraries.
The build directory of the CMake project must contain the compile_commands.json file, CMake File API request file, and CMake File API response file. The details are as follows.
File | Description |
|---|---|
compile_commands.json | This is a compilation database file that records the compilation commands, header file paths, and macro definitions for each source file. Path: Build directory/compile_commands.json |
CMake File API request file | This file is used to notify CMake of the build information required in the configuration phase. Path: Build directory/.cmake/api/v1/query/codemodel-v2 |
CMake File API response file | This file is automatically generated by CMake during configuration. It describes the structure of the build system in JSON format for parsing by DevEco Studio, enabling code reading, breakpoint debugging, issue locating, and other functions. Path: Build directory/.cmake/api/v1/reply/ |
Run the following commands to generate the compile_commands.json file and codemodel-related files.
mkdir build_ohos
cmake -E make_directory build_ohos/.cmake/api/v1/query cmake -E touch build_ohos/.cmake/api/v1/query/codemodel-v2
cmake -S entry/src/main/cpp -B build_ohos -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE="DevEco Studio installation directory/deveco-studio/sdk/default/openharmony/native/build/cmake/ohos.toolchain.cmake" -G Ninja
cmake --build build_ohos












Choose File > Sync and Refresh Project to synchronize the project and wait for indexing to finish.
