title: How to build external C++ library with Android Studio + Gradle + NDK?
body: <p>I'm porting C++ library to Android now. I did initial work already and got it build in Application.mk/Android.mk way. </p>
  
  <p>The upcoming Java demo application for library is developing in Android Studio now. I can built everything (demo + library) together - thanks to StackOverflow community.  </p>
  
  <p>However I have no access to native debugging in these builds. But debugging is necessary - library is not stable enough yet. Pure console GDB debugging takes too much time for now and can consume more hours in future.</p>
  
  <p>So I decided to make build with Android Studio and Gradle to use integrated debugger.</p>
  
  <p>I have dedicated library module with NDK and Java (wrapper) parts.
  However C/C++ source files are not under jni/ subdirectory. They are located in another directory. </p>
  
  <p>Therefore I can configure Gradle to get sources from that directory.
  I tried smth like this:</p>
  
  <pre><code>apply plugin: 'com.android.model.library'
  
  model {
  android {
      compileSdkVersion = 23
      buildToolsVersion = "23.0.2"
  
      defaultConfig.with {
          minSdkVersion.apiLevel = 10
          targetSdkVersion.apiLevel = 23
          versionCode = 1
          versionName = "1.0"
      }
  
      ndk {
          moduleName = "inttalksdk"
          stl "gnustl_shared"
          cppFlags.add("-std=c++11")
          cppFlags.add("-fexceptions")
          ldLibs.addAll(['log'])
      }
  }
  
  android.sources {
      main.jni.source {
          srcDirs.add(["src"])
      }
  }
  
  
  android.buildTypes {
      release {
          minifyEnabled = false
          proguardFiles.add(file('proguard-android.txt'))
      }
  }
  }
  </code></pre>
  
  <p>But AS cannot sync project even.
  Error message is:</p>
  
  <pre><code>Gradle 'Android' project refresh failed
  Error:Attempt to read a write only view of model of type 'java.lang.Object' given to rule 'android.sources { ... } @ inttalksdk/build.gradle line 24, column 5'
  </code></pre>
  
  <p>My true question is: how to add these external C/C++ files into Gradle build?</p>
  
  <p>I use latest AS 2.0 + 0.7.0 beta3 experimental plugin.</p>
  
  <p>Please help.</p>