apply plugin: 'com.android.application'

android {
    if (project.hasProperty('RELEASE_STORE_FILE')) {
      // https://stackoverflow.com/a/21020469
      signingConfigs {
        release {
          storeFile file(RELEASE_STORE_FILE)
          storePassword RELEASE_STORE_PASSWORD
          keyAlias RELEASE_KEY_ALIAS
          keyPassword RELEASE_KEY_PASSWORD
        }
      }

      buildTypes {
        release {
          minifyEnabled true
          proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                  'proguard-rules.pro'
          signingConfig signingConfigs.release
          debuggable false
          jniDebuggable false
          renderscriptDebuggable false
        }
      }
    }

    compileSdkVersion 27

    defaultConfig {
        applicationId 'com.elucideye.facefilter'

        // https://developer.android.com/reference/android/support/v4/app/ActivityCompat#requestpermissions
        // See FaceFilterCameraManager.java
        minSdkVersion 24

        targetSdkVersion 27
        externalNativeBuild {
            cmake {
                arguments '-DANDROID_STL=c++_static',
                    '-DFACEFILTER_ANDROID_STUDIO=1',
                    '-DHUNTER_STATUS_DEBUG=ON',
                    '-DCMAKE_VERBOSE_MAKEFILE=ON'
                    '-DDRISHTI_OPENGL_ES3=ON'
            }
        }

        version 5
    }

    externalNativeBuild {
        if (project.hasProperty('loadParentProject')) {
            println 'Loading top level project'
            cmake {
                 path '../../../../../CMakeLists.txt'
            }
        }
        else {
            println 'Loading example project'
            cmake {
                 path '../../../CMakeLists.txt'
            }
        }
    }

    splits {
        if (project.hasProperty('arch')) {
            abi {
                enable true

                reset()
                include project.property('arch')

                universalApk false
            }
        }
        else {
            abi {
                enable true

                reset()
                //include 'x86_64', 'armeabi-v7a', 'arm64-v8a'
                include 'arm64-v8a'

                universalApk false
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation "com.android.support:support-v4:27.0.2"
    implementation "com.android.support:support-v13:27.0.2"
    implementation "com.android.support:cardview-v7:27.0.2"
    implementation "com.android.support:appcompat-v7:27.0.2"
}

//ext.abiCodes = ['x86_64':1, 'armeabi-v7a':3, 'arm64-v8a':4]
ext.abiCodes = ['arm64-v8a':4]

import com.android.build.OutputFile

android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def baseAbiVersionCode = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
        if (baseAbiVersionCode != null) {
            output.versionCodeOverride = baseAbiVersionCode * 1000 + variant.versionCode
        }
    }
}
