def ofRoot(){ return '../../../' }

// Load common functions
apply from: ofRoot()+"libs/openFrameworksCompiled/project/android/common-functions.gradle"

buildscript {
    apply from: "../../../libs/openFrameworksCompiled/project/android/ndk-verify.gradle"

    repositories {
        jcenter()
    }
    dependencies {
        // Using the gradle-experimental version that supports c++
        classpath 'com.android.tools.build:gradle-experimental:0.9.3'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

apply plugin: 'com.android.model.application'

model {
    android {
        // openFrameworks currently only supports compiling against SDK 19
        compileSdkVersion = 19
        buildToolsVersion = "25.0.3"

        defaultConfig.with {
            minSdkVersion.apiLevel    = 24
            targetSdkVersion.apiLevel = 24
            versionCode     =  1
            versionName     = "1.0"
        }
    }

    android.ndk {
        moduleName = ofAppModuleName()
        toolchain  = buildToolchain()
        stl        = compilerStl()
    }

    android.sources {
        main {
            jni {
                source {
                    srcDirs= appSrcDirs(ofRoot())

                    includes = srcIncludes(ofRoot())
                    excludes = srcExcludes(ofRoot())
                }

                // Link to openFrameworks
                dependencies {
                    project ":openFrameworksProject"  linkage "static"
                }
            }

            manifest {
                source {
                    srcDirs = [ "." ]
                }
            }
            res {
                source {
                    srcDirs = [ "res" ]
                }
            }
            java {
                source {
                    srcDirs = [ "srcJava" ]
                }
            }
            aidl {
                source{
                    srcDirs = ['srcJava']
                }
            }
            renderscript{
                source{
                    srcDirs = ['srcJava']
                }
            }
            jniLibs {
                source {
                    srcDirs = ['libs']
                }
            }
            assets {
                source {
                    srcDirs = ['bin/data'] + addonData(ofRoot())
                }
            }
        }
    }

    android.lintOptions {
        abortOnError  = false
    }

    android.buildTypes {
        release {
            minifyEnabled = false
        }
    }

    // Setup the different types of flavors (arm / x86),
    // and add linker flags based on that
    android.productFlavors {
        getAbis().each { abi ->
            create(getFlavorName(abi)) {
                ndk {
                    abiFilters.add(abi)

                    cppFlags.addAll(coreCppFlags(abi, ofRoot()))
                    cppFlags.addAll(addonCppFlags(abi, ofRoot()))

                    ldLibs.addAll(coreLdLibs(abi, ofRoot()))
                    ldLibs.addAll(addonLdLibs(abi, ofRoot()))

                    ldFlags.addAll(coreLdFlags(abi, ofRoot()))
                    ldFlags.addAll(addonLdFlags(abi, ofRoot()))
                }
            }
        }
    }
}


dependencies {
    addonJavaDependencies(ofRoot()).each { dep ->
        compile(project(path: dep[1] ))
    }
    compile project(path: ':ofAndroidLib')
}
