目录

Batch Import and Batch Removal of .so Libraries

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.

Usage Instructions

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.

  1. Create a build directory in the project directory, for example, build_ohos.

    mkdir build_ohos

  2. Create a CMake File API request file.

    cmake -E make_directory build_ohos/.cmake/api/v1/query
    cmake -E touch build_ohos/.cmake/api/v1/query/codemodel-v2

  3. Perform CMake configuration.

    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

  4. Build the project.

    cmake --build build_ohos

  5. The directory structure is as follows:

Batch Import of .so Libraries

  1. Click Project in the navigation tree on the left to expand the project directory, and copy the .so library files to be imported to the libs directory of the module.

  2. Choose File > Sync and Refresh Project to synchronize the project.

  3. Right-click External Libraries and choose Import Source Code of .so Library from the shortcut menu.

  4. Click the folder icon at the end of .so Mapping File to open File Explorer.

  5. Select the configuration description file of the CMake project codemodel-v2-xxxx.json (path: Build directory/.cmake/api/v1/reply/codemodel-v2-xxxx.json) and click OK.

  6. The tool automatically parses and displays the matched .so libraries. You can select one or multiple libraries, or filter by keywords in the search bar. Check the target items and click OK.

  7. After the import is complete, click OK.

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

Batch Removal of .so Libraries

  1. Click Project in the navigation tree on the left to expand the project directory, right-click External Libraries, and choose Remove Source Code of .so Library from the shortcut menu.

  2. In the displayed dialog box, only successfully imported .so libraries are listed. Select the .so libraries to be removed directly or filter them using the search box, and click OK.

  3. After the removal is complete, click OK.

  4. Synchronize the project.

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