We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

必須Cookiesのみ
すべて同意
GuidesCANNApp DevelopmentIntegrationHarmonyOS App IntegrationConfiguring NAPI for Your Project

Configuring NAPI for Your Project

When building the NAPI of the inference model, for example, in a NPU-based scenario, you need to pack libhiai.so, libhiai_ir.so (optional), libhiai_ir_build.so (optional), libhiai_ir_build_aipp.so (optional), and libentry.so when packing the HAP, where libentry.so is the binary file for the demo packed using NAPI.

Compiling CMakeLists.txt

The CMakeLists.txt file is as follows:

# Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(CANNDemo)
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${NATIVERENDER_ROOT_PATH}
                    ${NATIVERENDER_ROOT_PATH}/include)
add_library(libhiai SHARED IMPORTED )
set_target_properties(libhiai PROPERTIES IMPORTED_LOCATION
        ${NATIVERENDER_ROOT_PATH}/../../../libs/arm64-v8a/libhiai.so)
add_library(libhiai_ir SHARED IMPORTED )
set_target_properties(libhiai_ir PROPERTIES IMPORTED_LOCATION
        ${NATIVERENDER_ROOT_PATH}/../../../libs/arm64-v8a/libhiai_ir.so)
add_library(libhiai_ir_build SHARED IMPORTED )
set_target_properties(libhiai_ir_build PROPERTIES IMPORTED_LOCATION
        ${NATIVERENDER_ROOT_PATH}/../../../libs/arm64-v8a/libhiai_ir_build.so)
add_library(libhiai_ir_build_aipp SHARED IMPORTED )
set_target_properties(libhiai_ir_build_aipp PROPERTIES IMPORTED_LOCATION
        ${NATIVERENDER_ROOT_PATH}/../../../libs/arm64-v8a/libhiai_ir_build_aipp.so)
add_library(entry SHARED Classification.cpp HIAIModelManager.cpp)
target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so librawfile.z.so)
target_link_libraries(entry LINK_PUBLIC
    libhiai			# Mandatory
    libhiai_ir			# Mandatory only for IR graph building
    libhiai_ir_build		# Mandatory only for IR graph building
    libhiai_ir_build_aipp.so	# Mandatory only for AIPP-based IR graph building
)

Copying .so Files of the DDK to the Project

Copy .so files of the CANN DDK to the corresponding location of the project. In the demo, the .so files are stored under the entry/libs directory.

Copying Header Files of the DDK to the Project

Copy header files of the CANN DDK to the corresponding location of the project. In the demo, the header files are stored under the entry/src/main/cpp/include directory.

Search in Guides
Enter a keyword.