开发步骤
- 安装devcostudio打开
- File->New->CreateProject->Native C++
cd src/main && git clone https://github.com/freetype/freetype && mv freetype/* cpp/- 多平台配置
新增build-profile.json5下abiFilters,支持多平台
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "",
"cppFlags": "",
"abiFilters": [
"x86_64",
"arm64-v8a"
]
} - 点击锤子🔨make module生成,右上角圆点切换debug|release。输出文件在build\default\outputs\default\*.hap,解压有ABI对应的.so文件。
- ts或其它库调用使用时,需在src同级目录下新建libs文件夹,拷贝abiFilters所有文件夹到libs下。
.so cmake配置
cmake_minimum_required(VERSION 3.5.0) project(NativeFileAccess) set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) if(DEFINED PACKAGE_FIND_FILE) include(${PACKAGE_FIND_FILE}) endif() include_directories(${NATIVERENDER_ROOT_PATH} ${NATIVERENDER_ROOT_PATH}/include) link_directories(${NATIVERENDER_ROOT_PATH}/../../../libs/${OHOS_ARCH}) add_library(file_access SHARED FileAccessMethods.cpp) if (CMAKE_BUILD_TYPE STREQUAL "Debug") set_property(TARGET file_access PROPERTY IMPORTED_LOCATION ${NATIVERENDER_ROOT_PATH}/libs/${OHOS_ARCH}/libfreetyped.so) else() set_property(TARGET file_access PROPERTY IMPORTED_LOCATION ${NATIVERENDER_ROOT_PATH}/libs/${OHOS_ARCH}/libfreetype.so) endif () set_property(TARGET file_access PROPERTY IMPORTED_LOCATION ${NATIVERENDER_ROOT_PATH}/libs/${OHOS_ARCH}/libc++_shared.so) target_link_libraries(file_access PUBLIC libace_napi.z.so libhilog_ndk.z.so librawfile.z.so libc++_shared.so) target_link_libraries(file_access PUBLIC debug libfreetyped.so optimized libfreetype.so)库依赖查看
readelf -d lib.so
注:so.x.x不支持,需用.so加载
参考
https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-compiling-and-building-86
https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-access-control-14
https://gitee.com/openharmony-sig/tpc_c_cplusplus.git
https://github.com/AiMiDi/icu-cmake
https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-ndk-72
https://gitee.com/harmonyos_samples/NativeFileAccess
https://gitee.com/harmonyos_samples/hiaifoundationkit-samplecode-clientdemo-cpp
https://gitee.com/harmonyos_samples/native-multi-threads