- 下载 HiAI Engine SDK 并解压缩。
- 在 Android Studio 中选择您的项目,然后右键单击“app”文件夹。选择“New” -> “Folder” -> “JNI Folder”。
- 将解压缩后的 HiAI Engine SDK 文件夹复制到您的“jni”文件夹中。此时,您的项目结构应如下所示:
app/
-- src/
---- main/
------ java/
------ jni/
-------- huawei/
---------- hiai/
------------ libhiai.so
------ jniLibs/
-------- arm64-v8a/
---------- libhiai.so
-------- armeabi-v7a/
---------- libhiai.so
-------- x86_64/
---------- libhiai.so
-------- x86/
---------- libhiai.so
- 在您的“app/build.gradle”文件中添加以下内容:
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
cFlags '-std=c++11'
}
}
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(fileTree(dir: "${project.rootDir}/src/main/jniLibs", include: ['*.so']))
}
- 编辑“CMakeLists.txt”文件,添加以下内容:
cmake_minimum_required(VERSION 3.10.2)
project(hello)
include_directories(${HELLO_SOURCE_DIR}/../../../../../../../../..)
include_directories(${HELLO_SOURCE_DIR}/../../../../../../../../../*/inc)
include_directories(${HELLO_SOURCE_DIR}/../../../../../../../../../*/include)
add_library(hiai SHARED IMPORTED)
set_target_properties(hiai PROPERTIES IMPORTED_LOCATION "${HELLO_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libhiai.so")
add_library(hello SHARED hello.cpp)
find_library(log-lib log)
target_link_libraries(hello hiai ${log-lib})
- 点击“Sync Now