apply plugin: 'com.android.library'

android {
  compileSdkVersion 26

  defaultConfig {
    minSdkVersion 24
    targetSdkVersion 25

    externalNativeBuild {
      ndk {
        abiFilters 'arm64-v8a'
      }
      ndkBuild {
        targets "samplecommon"

        def numProcs = Runtime.runtime.availableProcessors()
        arguments "V=0", "-j$numProcs", "-C$project.buildDir.parent"
        abiFilters 'arm64-v8a'
      }
    }
  }

  externalNativeBuild {
    ndkBuild {
      path 'jni/Android.mk'
    }
  }

  buildTypes {
    debug {
      debuggable true
      jniDebuggable true

      externalNativeBuild {
        ndkBuild {
          arguments "NDK_DEBUG=1","OVR_DEBUG=1","USE_ASAN=1"
        }
      }
    }

    release {
      debuggable false
      jniDebuggable false

      externalNativeBuild {
        ndkBuild {
          arguments "NDK_DEBUG=0","OVR_DEBUG=0","USE_ASAN=0"
        }
      }
    }
  }

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      java.srcDirs = ['../../java']
      res.srcDirs = ['../../res']
    }
  }
}

task( "cleanWorkAround" ) {
    description "Workaround for .externalNativeBuild not being deleted on clean"
}.doLast {
    project.delete project.file( ".externalNativeBuild" )
}

// WORKAROUND: On Mac OS X, running ndk-build clean with a high num of parallel executions
// set may result in the following build error:  rm: fts_read: No such file or directory.
// Currently, there isn't a good way to specify numProcs=1 only on clean. So, in order
// to work around the issue, delete the auto-generated .externalNativeBuild artifacts
// (where $numProcs specified) before executing the clean task.
clean.dependsOn cleanWorkAround
