How to use the recompiled build of OpenCV for Android

So I want to change one of the files in the OpenCV assembly for Android, and I followed the instructions on their site to download the assembly, and I was able to make it successful. I changed one of the files (calibinit.cpp) and made it again and copied the files to

OpenCV / platforms / build_android_arm / Library /

to the jniLibs folder of my AndroidStudio Project.

However, the changes I made definitely do not work. I already had the previous OpenCV library related to my project, so I'm sure it still uses the old code. How to use the new assembly with my AndroidStudio Project?

+5
source share
2 answers

Can you provide more details on how to use jni in an Android Studio project?

  • Are you trying to clean and rebuild?
  • Do you have your own custom Android.mk? the reason Android Studio will generate its own Android.mk, which may lead to an unexpected result, as I thought.
0
source
  • delete the jniLibs folder and each such file, you do not need them.
  • Define the NDK path in the local.properties file:
    sdk.dir = D: \ Android \ SDK
    ndk.dir = D: \ Android \ NDK
  • create a folder (I named it jni) and put Android.mk and Application.mk in it (and an empty dummy.c file to prevent errors in the future)
  • as Roy said, Android Studio creates its own Android.mk, we have our own Android.mk file, and Android Studio must use it. jni.srcDirs = [] prevents this generation!
  • Extract openCV sources somewhere, I will put them here: D:\Android\Libs\OpenCV
  • here are my files, modify and use them

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) 
0
source

All Articles