title: OpenCv with Android studio 1.3+ using new gradle - undefined reference
body: <p>I'm having trouble using native OpenCv 2.4.11 (3.0.0 is also ok) with Android Studio 1.3+, with new ndk support. All tutorials about .mk files, but I want to use it with new experimental gradle.<br/>
  Using Kiran answer <a href="https://stackoverflow.com/questions/27406303/opencv-in-android-studio">OpenCV in Android Studio</a>
  I achived to work fine in java. Also I have changed <br/>gradle-wrapper.properties: 
  <br/><br/>
      <code>distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip</code>
  <br/><br/>
  build.gradle(application):</p>
  
  <pre><code>classpath 'com.android.tools.build:gradle-experimental:0.2.0'
  </code></pre>
  
  <p><br/><br/>
  build.gradle(module):</p>
  
  <pre><code>apply plugin: 'com.android.model.application'
  
  model {
      android {
          compileSdkVersion = 23
          buildToolsVersion = "23.0.0"
  
          defaultConfig.with {
              applicationId = "android.overloaded.nativetestv4"
              minSdkVersion.apiLevel = 18
              targetSdkVersion.apiLevel = 23
              versionCode = 1
              versionName = "1.0"
          }
      }
  
      android.ndk{
          moduleName = "mymodule"
          ldLibs += ['log']
          cppFlags += "-std=c++11" 
          cppFlags += "-fexceptions"
          cppFlags  += "-I${file("C:/DevAndroid/OpenCV-android-sdk/sdk/native/jni/include")}".toString()
          cppFlags  += "-I${file("C:/DevAndroid/OpenCV-android-sdk/sdk/native/jni/include/opencv")}".toString()
  
          ldLibs += ["android", "EGL", "GLESv2", "dl", "log", "z"] //added z
          stl = "stlport_static"//"gnustl_shared" changed to stlport static
      }
  
      android.buildTypes {
          release {
              minifyEnabled = false
              proguardFiles += file('proguard-rules.pro')
          }
      }
      android.productFlavors { //added all productFlavors code
          create("arm") {
              ndk.with {
                  abiFilters += "armeabi"
                  File curDir = file('./')
                  curDir = file(curDir.absolutePath)
                  String libsDir = curDir.absolutePath+"\\src\\main\\jniLibs\\armeabi\\" //"-L" +
                  ldLibs += libsDir + "libnative_camera_r4.3.0.so"
                  ldLibs += libsDir + "libopencv_contrib.a"
                  ldLibs += libsDir + "libopencv_core.a"
                  ldLibs += libsDir + "libopencv_highgui.a"
                  ldLibs += libsDir + "libopencv_imgproc.a"
                  ldLibs += libsDir + "libopencv_info.so"
                  ldLibs += libsDir + "libopencv_java.so"
                  ldLibs += libsDir + "libopencv_legacy.a"
                  ldLibs += libsDir + "libopencv_ml.a"
                  ldLibs += libsDir + "libopencv_ts.a"
              }
          }
          create("armv7") {
              ndk.with {
                  abiFilters += "armeabi-v7a"
                  File curDir = file('./')
                  curDir = file(curDir.absolutePath)
                  String libsDir = curDir.absolutePath+"\\src\\main\\jniLibs\\armeabi-v7a\\" //"-L" +
  
                 ldLibs += libsDir + "libnative_camera_r4.3.0.so"
                 ldLibs += libsDir + "libopencv_contrib.a"
                 ldLibs += libsDir + "libopencv_core.a"
                 ldLibs += libsDir + "libopencv_highgui.a"
                 ldLibs += libsDir + "libopencv_imgproc.a"
                 ldLibs += libsDir + "libopencv_info.so"
                 ldLibs += libsDir + "libopencv_java.so"
                 ldLibs += libsDir + "libopencv_legacy.a"
                 ldLibs += libsDir + "libopencv_ml.a"
                 ldLibs += libsDir + "libopencv_ts.a"
              }
           }
           create("fat") {
           }
       }
      dependencies {
          compile fileTree(include: ['*.jar'], dir: 'libs')
          compile 'com.android.support:appcompat-v7:23.0.0'
          compile project(':openCVLibrary2411')
      }
  </code></pre>
  
  <p>With this changes I can call my native dummy function in c++ file under jni folder. Also <code>#include &lt;opencv2/core/core.hpp&gt;</code> and others are supported by CLion... When I declare cv::Mat mat; gives me this error:<br/></p>
  
  <pre><code>Linker failed while linking libmymodule.so failed.
  C:\DevAndroid\OpenCV-android-sdk\sdk\native\jni\include/opencv2/core/mat.hpp:278: error: undefined reference to 'cv::fastFree(void*)'
  C:\DevAndroid\OpenCV-android-sdk\sdk\native\jni\include/opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>c++ code:</p>
  
  <pre><code>#include &lt;jni.h&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include "helpers.h"
  #include &lt;opencv2/core/core.hpp&gt; //This is supported by CLion
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  using namespace std;
  
  extern "C" {
  JNIEXPORT jstring JNICALL
  Java_android_overloaded_nativetestv4_MainActivity_FuncV1(JNIEnv *env, jclass type) {
      cv::Mat mat; //causing error
  
      string s = "Cpp v1 - succ ";
      return env-&gt;NewStringUTF(s.data());
  }
  
  }
  </code></pre>
  
  <p><strong>Update</strong><br/><br/>
  - added "z" to ldLibs<br/>
  - added android.productFlavors block</p>
  
  <p>Now compilation is successfull, application starts for second and then crashes with this messages<br/>
  Event log:</p>
  
  <pre><code>IllegalArgumentException: Error while starting native debug session: Unable to find process for android.overloaded.nativetestv4 on device huawei-huawei_y530_u00-64a6513ccd8e
  </code></pre>
  
  <p>Debug info:</p>
  
  <pre><code>Restart ADB integration and try again
  Waiting for process: android.overloaded.nativetestv4
  DEVICE SHELL COMMAND: run-as android.overloaded.nativetestv4 mkdir -p /data/data/android.overloaded.nativetestv4/lldb/bin
  DEVICE SHELL COMMAND: cat /data/local/tmp/lldb-server | run-as android.overloaded.nativetestv4 sh -c 'cat &gt; /data/data/android.overloaded.nativetestv4/lldb/bin/lldb-server; chmod 700 /data/data/android.overloaded.nativetestv4/lldb/bin/lldb-server'
  DEVICE SHELL COMMAND: rm /data/local/tmp/lldb-server
  DEVICE SHELL COMMAND: cat /data/local/tmp/start_lldb_server.sh | run-as android.overloaded.nativetestv4 sh -c 'cat &gt; /data/data/android.overloaded.nativetestv4/lldb/bin/start_lldb_server.sh; chmod 700 /data/data/android.overloaded.nativetestv4/lldb/bin/start_lldb_server.sh'
  DEVICE SHELL COMMAND: rm /data/local/tmp/start_lldb_server.sh
  Now Launching Native Debug Session
  Error while starting native debug session: java.lang.IllegalArgumentException: Unable to find process for android.overloaded.nativetestv4 on device huawei-huawei_y530_u00-64a6513ccd8e
  </code></pre>
  
  <p>log:</p>
  
  <pre><code>A/libc﹕ Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 3077 (ed.nativetestv4)
  </code></pre>