所以我想修改Android的OpenCV版本中的一个文件,然后按照their site上的说明下载构建,我就能成功完成。我修改了其中一个文件(calibinit.cpp)并重新制作并复制了
中的文件的OpenCV /平台/ build_android_arm / LIB /
将文件夹放入我的AndroidStudio项目的jniLibs文件夹中。
然而,我所做的改变绝对不起作用。我已经有一个以前的OpenCV库链接到我的项目,所以我很确定它仍在使用旧代码。如何在我的AndroidStudio项目中使用新版本?
答案 0 :(得分:0)
您能否提供有关如何在Android Studio Project中使用jni的更多详细信息?
答案 1 :(得分:0)
local.properties
文件中定义NDK路径:jni.srcDirs = []
可以防止这一代!D:\Android\Libs\OpenCV
<强> 的build.gradle: 强>
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "your.package"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
sourceSets {
main {
jni.srcDirs = [] /*disables automatic ndk-build call */
}
}
task ndkBuild(type: Exec) {
commandLine file('D:\\Android\\NDK\\ndk-build.cmd').absoluteFile,
'NDK_PROJECT_PATH='+file('src\\main\\jni').absolutePath,
'APP_BUILD_SCRIPT='+file('src\\main\\jni\\Android.mk').absolutePath,
'NDK_APPLICATION_MK='+file('src\\main\\jni\\Application.mk').absolutePath,
'NDK_LIBS_OUT='+file('src\\main\\jniLibs').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile project(':openCVLibrary300rc1')
}
<强> Application.mk: 强>
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a x86
APP_PLATFORM := android-8
<强> Android.mk: 强>
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#opencv
OPENCVROOT:= D:/Android/Libs/OpenCV
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
//I have a local source file, you can remove it
LOCAL_SRC_FILES := DetectionBasedTracker_jni.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS += -llog
LOCAL_MODULE := detection_based_tracker
include $(BUILD_SHARED_LIBRARY)