c++ - Building native OpenCV using Android NDK gives "undefined reference to 'cv::String::deallocate()'" -


i'm attempting use opencv ndk in android studio. may notice i'm using native library called gstreamer.

my build.gradle:

apply plugin: 'com.android.application'  def getndkcommandline(ndkroot, target) {     def gstroot     def opencvroot     gstroot = 'c:/local/gstreamer-1.0-android-arm-1.8.0'     opencvroot = 'c:/local/opencv-3.1.0-android-sdk/opencv-android-sdk'      if (ndkroot == null)         throw new gradleexception('ndk not configured')      return ["$ndkroot/ndk-build.cmd",             'ndk_project_path=build',             'app_build_script=src/main/jni/android.mk',             'ndk_application_mk=src/main/jni/application.mk',             'gstreamer_java_src_dir=src/main/java',             "gstreamer_root_android=$gstroot",             "opencv_root_android=$opencvroot",             "$target"] }  android {     compilesdkversion 19     buildtoolsversion "23.0.2"      sourcesets {         main {             // avoid using built in jni generation plugin             jni.srcdirs = []             jnilibs.srcdirs = ['build/libs']         }     }      defaultconfig {         applicationid "com.mytestcom.mytestapp"         minsdkversion 19         targetsdkversion 19         compileoptions {             sourcecompatibility javaversion.version_1_7             targetcompatibility javaversion.version_1_7         }     }      buildtypes {         release {             minifyenabled false             proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.txt'             signingconfig signingconfigs.release         }     }      // before compiling our app, prepare ndk code     tasks.withtype(javacompile) {         compiletask -> compiletask.dependson ndkbuild     }      // need call clean on ndk ourselves     clean.dependson 'ndkclean'      // build native code using mk files on eclipse     task ndkbuild(type: exec, description: 'compile jni source via ndk') {         commandline getndkcommandline(android.ndkdirectory, 'target_arch_abi=armeabi-v7a')     }      task ndkclean(type: exec, description: 'clean jni code built via ndk') {         commandline getndkcommandline(android.ndkdirectory, 'clean')     }      //renames apk current versionname found in android manifest     applicationvariants.all { variant ->         variant.outputs.each { output ->             def outputfile = output.outputfile             if (outputfile != null && outputfile.name.endswith('.apk')) {                 def filename = "my_test_app-${versionname}.apk"                 output.outputfile = new file(outputfile.parent, filename)             }         }     } }  dependencies {     compile 'com.android.support:support-v4:19.1.0'     compile project(':opencvlibrary310') } 

android.mk:

local_path := $(call my-dir)  include $(clear_vars)  local_module := gstplayer local_src_files := player.cpp local_c_includes := $(opencv_root_android)/sdk/native/jni/include  local_shared_libraries := gstreamer_android local_ldlibs := -llog -landroid include $(build_shared_library)  ifeq ($(target_arch_abi),armeabi) gstreamer_root        := $(gstreamer_root_arm) else ifeq ($(target_arch_abi),armeabi-v7a) gstreamer_root        := $(gstreamer_root_armv7) else ifeq ($(target_arch_abi),arm64-v8a) gstreamer_root        := $(gstreamer_root_arm64) else ifeq ($(target_arch_abi),x86) gstreamer_root        := $(gstreamer_root_x86) else ifeq ($(target_arch_abi),x86_64) gstreamer_root        := $(gstreamer_root_x86_64) else $(error target arch abi not supported) endif  ifndef gstreamer_root ifndef gstreamer_root_android $(error gstreamer_root_android not defined!) endif gstreamer_root        := $(gstreamer_root_android) endif  gstreamer_ndk_build_path  := $(gstreamer_root)/share/gst-android/ndk-build/  include $(gstreamer_ndk_build_path)/plugins.mk gstreamer_plugins         := $(gstreamer_plugins_core) $(gstreamer_plugins_playback) $(gstreamer_plugins_codecs) $(gstreamer_plugins_net) $(gstreamer_plugins_sys) $(gstreamer_plugins_codecs_restricted) $(gstreamer_codecs_gpl) $(gstreamer_plugins_encoding) $(gstreamer_plugins_vis) $(gstreamer_plugins_effects) $(gstreamer_plugins_net_restricted) gstreamer_extra_deps      := gstreamer-player-1.0 gstreamer-video-1.0 glib-2.0  opencv_install_modules:=on opencv_cameramodules:=off opencv_lib_type:=static  include $(gstreamer_ndk_build_path)/gstreamer-1.0.mk include $(opencv_root_android)/sdk/native/jni/opencv.mk 

application.mk:

app_platform=android-19 app_stl := gnustl_static app_cppflags := -frtti -fexceptions app_abi := armeabi-v7a 

i'm using opencv-3.1.0-android-sdk, ndk r10e, android studio 2.1, windows. i've tried using different version of opencv (2.4.11) didn't help.

c:\local\opencv-3.1.0-android-sdk\opencv-android-sdk\sdk\native\jni\include\opencv2\core\cvstd.hpp error:(625) undefined reference 'cv::string::allocate(unsigned int)' error:(667) undefined reference 'cv::string::deallocate()' error:(667) undefined reference 'cv::string::deallocate()' error:(667) undefined reference 'cv::string::deallocate()' error:(667) undefined reference 'cv::string::deallocate()'  c:\local\opencv-3.1.0-android-sdk\opencv-android-sdk\sdk\native\jni\include\opencv2\core\mat.inl.hpp error:(443) undefined reference 'cv::error(int, cv::string const&, char const*, char const*, int)' error:(459) undefined reference 'cv::error(int, cv::string const&, char const*, char const*, int)' error:(682) undefined reference 'cv::mat::deallocate()' error:(571) undefined reference 'cv::fastfree(void*)' error:(592) undefined reference 'cv::mat::copysize(cv::mat const&)' 

i ran similar issue few days ago. imo, should try replace local_ldlibs := -llog -landroid local_ldlibs += -llog -landroid.


Comments