根据前面学习的c学习的基础知识,在as下,进行手动的ndk开发
1.在java类中先写native方法,并且加载将将要生成的c或c++的文件的名称
2.在terminal的命令行中输入命令生成头文件
javah -d ../jni com.xxx.xxx 。其中-d是生成文件夹的意思
3.在生成的jni,右键创建c或c++代码。
4.由于as现在支持cmake的构建ndk的方法,原有的方法比如在工程目录下的gradle.properties中添加
都是无效的。
因此应该app的gradle下面做相应的cmake的配置
在android–> defaultConfig下面添加
5.在android下面添加,否则会默认只生成一个平台的so文件
6.指定cmake文件的路径
7.创建CMakeLists.txt文件
8.CMakeLists.txt的内容,并根据提示进行响应的修改
cmake_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
JNIHello
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/jni/JNIHello.c )
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
JNIHello
# Links the target library to the log library
# included in the NDK.
${log-lib} )
9.最后在下面目录中找到so文件
其响应的配置都可以参考as默认创建的jni。在创建工程时,选择c++支持。就可以创建默认应用。