Building native OpenCV using Android NDK gives "undefined reference to 'cv::String::deallocate()'"
<p>I'm attempting to use OpenCV with the NDK in Android Studio. As you may notice I'm using another native library called GStreamer.</p>

<p>My build.gradle:</p>

<pre><code>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 the 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 -&gt; compileTask.dependsOn ndkBuild
    }

    // Need to call clean on NDK ourselves too
    clean.dependsOn 'ndkClean'

    // Build native code using mk files like 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 to current versionName found in Android Manifest
    applicationVariants.all { variant -&gt;
        variant.outputs.each { output -&gt;
            def outputFile = output.outputFile
            if (outputFile != null &amp;&amp; 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')
}
</code></pre>

<p>Android.mk:</p>

<pre><code>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 is 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
</code></pre>

<p>Application.mk:</p>

<pre><code>APP_PLATFORM=android-19
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
</code></pre>

<p>I'm using OpenCV-3.1.0-android-sdk, NDK r10e, Android Studio 2.1, Windows. I've tried using a different version of OpenCV (2.4.11) but it didn't help.</p>

<pre><code>C:\local\OpenCV-3.1.0-android-sdk\OpenCV-android-sdk\sdk\native\jni\include\opencv2\core\cvstd.hpp
Error:(625) undefined reference to 'cv::String::allocate(unsigned int)'
Error:(667) undefined reference to 'cv::String::deallocate()'
Error:(667) undefined reference to 'cv::String::deallocate()'
Error:(667) undefined reference to 'cv::String::deallocate()'
Error:(667) undefined reference to '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 to 'cv::error(int, cv::String const&amp;, char const*, char const*, int)'
Error:(459) undefined reference to 'cv::error(int, cv::String const&amp;, char const*, char const*, int)'
Error:(682) undefined reference to 'cv::Mat::deallocate()'
Error:(571) undefined reference to 'cv::fastFree(void*)'
Error:(592) undefined reference to 'cv::Mat::copySize(cv::Mat const&amp;)'
</code></pre>