title: linking against .so files in a .aar file using android gradle experimental
body: <p>I am using the android gradle experimental plugin to build an app module with some native code. This native code uses a library with pre-built .so files, which I am bundling into a .aar file via an android library module. The .aar file builds fine, but how do I link the native code module in the app module to the pre-built .so files in the .aar module? The gradle experimental documentation doesn't mention this scenario.</p>
  
  <p>Also, I'd like to package up include files in the .aar file if possible (although they shouldn't be packaged with the final application).</p>
  
  <p>In /prebuiltlib:</p>
  
  <pre><code>build.gradle
  -src/
  --main/
  ---jniLibs/
  ----libfoo.so
  </code></pre>
  
  <p>Here are the gradle files:</p>
  
  <p>/prebuiltlib/build.gradle</p>
  
  <pre><code>apply plugin: "com.android.model.library"
  model {
      android {
          compileSdkVersion 25
          buildToolsVersion "25.0.3"
  
          defaultConfig {
              minSdkVersion.apiLevel = 21
              targetSdkVersion.apiLevel = 21
              versionCode 1
              versionName "1.0"
  
          }
  
          buildTypes {
              release {
                  minifyEnabled false
                  proguardFiles.add(file("proguard-rules.pro"))
              }
          }
      }
  }
  
  dependencies {
      compile fileTree(dir: "libs", include: ["*.jar"])
      compile "com.android.support:appcompat-v7:25.3.1"
  }
  </code></pre>
  
  <p>Here is /app/build.gradle, note the ??? where I'm not sure what to put:</p>
  
  <pre><code>import org.apache.tools.ant.taskdefs.condition.Os
  apply plugin: 'com.android.model.application'
  
  model {
      repositories {
          libs(PrebuiltLibraries) {
              // ??? is this right, and does this go into app/build.gradle or mylib/build.gradle?
              foo {
                  binaries.withType(SharedLibraryBinary) {
                      sharedLibraryFile = file('???/libfoo.so')
                  }
              }
          }
      }
      android {
          compileSdkVersion = 25
          buildToolsVersion = '25.0.3'
  
          defaultConfig {
              applicationId = 'com.jeremy.stackoverflow.sample'
              minSdkVersion.apiLevel = 21
              targetSdkVersion.apiLevel = 21
              versionCode = 1
              versionName = '1.0'
          }
  
          ndk {
              platformVersion = 21
              moduleName = 'native-activity'
              toolchain = 'gcc'
              toolchainVersion = '4.9'
              stl = 'gnustl_shared'
              abiFilters.add('armeabi-v7a')
              ldLibs.addAll(['log',
                             'android',
                             'EGL',
                             'GLESv2'
              ])
              // ??? How do I add include paths from the .aar module?
              cppFlags.add('-I' + file('???/include'))
              cppFlags.addAll(['-std=c++11', '-fexceptions'])
          }
  
          sources {
              main {
                  jni {
                      dependencies {
                          // ??? Is this right?
                          library 'foo' linkage 'shared'
                      }
                  }
                  jniLibs {
                      source {
                          // ??? Do I need one of these for the libs in the .aar?
                          srcDir file('???/jniLibs')
                      }
                      dependencies {
                          // ??? Is this right?
                          library 'foo'
                      }
                  }
              }
          }
          buildTypes {
              release {
                  minifyEnabled = false
                  proguardFiles.add(file('proguard-rules.pro'))
              }
          }
      }
  }
  
  dependencies {
      println rootProject.getName()
      compile fileTree(include: ['*.jar'], dir: 'libs')
      compile 'com.android.support:appcompat-v7:25.3.1'
      compile project(':prebuiltlib')
  }
  </code></pre>