在linux环境下编译android so库
(1) 配置Android NDK环境
https://developer.android.google.cn/ndk/downloads/older_releases.html
1.下载android-ndk64-r10b-linux-x86_64.tar.bz2,下载地址:http://dl.google.com/android/ndk/android-ndk64-r10b-linux-x86_64.tar.bz2
2. 把下载好的android-ndk64-r10b版本解压
3.配置环境变量命令:$sudo gedit ~/.bashrc
添加以下代码:
export NDK=/home/davebobo/android-ndk-r10b
export PATH=${PATH}:$NDK 保存关闭。
5.source ~/.bashrc使其修改的文件生效。
6.ndk-build看看咱们配置环境变量成功没,只要没出command not found就证明环境变量配置成功,如果成功显示如下,
(2) Android mk文件编写
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # OpenCV OPENCV_CAMERA_MODULES:=on OPENCV_INSTALL_MODULES:=on OPENCV_LIB_TYPE:=STATIC #include D:\project\Android\OpenCV-2.4.10-android-sdk\sdk\native\jni\OpenCV.mk include $(LOCAL_PATH)/opencv_android/jni/OpenCV.mk LOCAL_MODULE := facequality LOCAL_SRC_FILES += facequality.cpp LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog LOCAL_CFLAGS += -ffast-math -lpthread -ldl -O3 -std=c++11 LOCAL_CFLAGS += -DBUILD_TBB=ON -DWITH_TBB=ON LOCAL_LDFLAGS += -Wl,--gc-sections LOCAL_CFLAGS += -fopenmp LOCAL_CPPFLAGS += -fopenmp LOCAL_LDFLAGS += -fopenmp LOCAL_LDLIBS += -lz -llog -ljnigraphics include $(BUILD_SHARED_LIBRARY)
Application.mk 编写
#Application.mk 控制编译的版本
APP_STL:=c++_shared
APP_CPPFLAGS:=-frtti -fexceptions
APP_ABI := arm64-v8a
(3) 目录文件
(4) 编译
$ ndk-build
[arm64-v8a] Compile++ : facequality <= facequality.cpp
jni/facequality.cpp:116:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.
[arm64-v8a] SharedLibrary : libfacequality.so
[arm64-v8a] Install : libfacequality.so => libs/arm64-v8a/libfacequality.so