自定义Application.mk Android.mk jni目录

2017-01-12 09:53:59来源:oschina作者:1071954237人点击

第七城市

ndk-build NDK_APPLICATION_MK=./Application.mk NDK_DEBUG=1


APP_BUILD_SCRIPT=$(APP_PROJECT_PATH)/cpp/Android.mk(相对于项目的位置)


Application.mk


APP_CPPFLAGS:=-frtti -fexceptions
APP_ABI:=armeabi armeabi-v7a x86
#APP_ABI:=x86
APP_OPTIM := debug
# In NDK r8e, we have to use GCC 4.7 for C++11 features like thread, mutex, etc.
#The default GCC is 4.6, which does NOT define macro _GLIBCXX_HAS_GTHREADS,
#so you’ll get errors like "mutex in namespace std does not name a type" etc.
#NDK_TOOLCHAIN_VERSION := 4.7
# GNU STL implements most C++11 features. Use either gnustl_static or gnustl_shared
#Without this your C++ code will not be able to access headers like ,
APP_STL := gnustl_static
APP_BUILD_SCRIPT=$(APP_PROJECT_PATH)/cpp/Android.mk

Android.mk


LOCAL_SRC_FILES := ../cpp/native-lib.cpp (相对于jni目录的位置)


LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=STATIC
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
#try to load OpenCV.mk from default install location
include C:/work-software/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
#include /opt/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
else
include $(OPENCV_MK_PATH)
endif
LOCAL_MODULE:= native-lib
#MY_CPP_LIST := $(wildcard $(LOCAL_PATH)/*.cpp)
#LOCAL_SRC_FILES := $(MY_CPP_LIST:$(LOCAL_PATH)/%=%)
LOCAL_SRC_FILES := ../cpp/native-lib.cpp
FILE_LIST := $(wildcard /opt/OpenCV-android-sdk/sdk/native/lib/arm64-v8a/*)
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -ljnigraphics
LOCAL_LDLIBS += -lz # Compression library
# C++11 and threading enabling features.
#Otherwise c++11, pthread, rtti and exceptions are not enabled by default
LOCAL_CPPFLAGS := -std=c++11 -pthread -frtti -fexceptions
include $(BUILD_SHARED_LIBRARY) android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.yyy"
versionCode 1
versionName '1.0'
minSdkVersion 10
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles ('proguard-android.txt')
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn 'ndkBuild', 'copyJniLibs'
}
sourceSets {
main {
jni.srcDirs = []
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
}
task ndkBuild(type: Exec) {
def ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
commandLine "$ndkDir/ndk-build.cmd", '-C', 'src/main/jni',
"NDK_OUT=$buildDir/ndk/obj",
"NDK_APP_DST_DIR=$buildDir/ndk/libs//$(TARGET_ARCH_ABI)"
}
task copyJniLibs(type: Copy) {
from fileTree(dir: file(buildDir.absolutePath + '/ndk/libs'), include: '**/*.so')
into file('src/main/jniLibs')
}
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台