环境
win7 64位
cmake 3.4.1
Android studio 3.1.3
之前看到网上有jni方式压缩图片,就看了一下,参照别人的代码进行了实验,但是结果怎么也无法编译通过。
参照博客:https://blog.csdn.net/hqiong208/article/details/53667661
使用CMakeLists文件方式编译,突然觉得这个比Android.mk文件编写起来简单一些,少了一堆
include $(CLEAR_VARS);
... include $(BUILD_SHARED_LIBRARY);
替代之后直接使用
add_library( # Sets the name of the library. [modulename] # Sets the library as a shared library. [moduletype (shared|static)] # Provides a relative path to your source file(s) [src_files] )
好了,不说废话了。这里列出了CMakeLists.txt中一些关键性的代码。
#配置jpeg.so 文件路径,此路径为绝对路径,经测试,相对路径不能编译通过,添加其他第三方库的时候也应该注意,${CMAKE_SOURCE_DIR}代表的是CMakeLists.txt所在目录绝对路径 set(lib_src_DIR ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}) #导入编译好的jpeg-turbo库 add_library(jpeg-and SHARED IMPORTED ) #这句话是jpeg对应的so文件,so文件是放到ibs这个文件夹中(相对与cpp这个文件的位置) set_target_properties(jpeg-and PROPERTIES IMPORTED_LOCATION ${lib_src_DIR}/libjpeg.so) #添加android log库 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 ) #添加jnigraphics,c++代码中使用到了AndroidBitmap,所以需要添加jnigrapics库 find_library( # Sets the name of the path variable. andbitmap jnigraphics ) add_library(zjybmcompress SHARED src/main/cpp/JpegCompress.cpp) target_link_libraries(zjybmcompress $