completing its build.
从系统查找依赖库
find_library( # Sets the name of the path variable.
#log日志库
log-lib
Specifies the name of the NDK library that
you want CMake to locate.
log )
Specifies libraries CMake should link to your target library. You
can link multiple libraries, such as libraries you define in this
build script, prebuilt third-party libraries, or system libraries.
库的依赖
target_link_libraries( # Specifies the target library.
native-lib
Links the target library to the log library
included in the NDK.
${log-lib} )
- native-lib.cpp
#include <jni.h>
#include
extern “C” JNIEXPORT jstring JNICALL
Java_com_kongge_ndktest_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = “Hello from C++”;
return env->NewStringUTF(hello.c_str());
}
- build.gradle
…
android {
defaultConfig {
externalNativeBuild {
cmake {
cppFlags “” // 命令参数,非必须
}
}
}
externalNativeBuild {
cmake {
path “src/main/cpp/CMakeLists.txt” // 指定了该文件的路径,必须
version “3.10.2” // 支持的最低版本,非必须
}
}
}
5.构建