apply plugin: 'com.android.application'

def ndkDir = null
if (project.rootProject.file('local.properties').exists()) {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    ndkDir = properties.getProperty('ndk.dir')
}
if (!ndkDir) {
    ndkDir = System.getenv("ANDROID_NDK_HOME")
}
if(!ndkDir || ndkDir.empty) {
    throw new GradleException('Environment Variable ANDROID_NDK_HOME for NDK path need to be setup')
}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.mr3d.app"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        ndk {
            abiFilters 'armeabi-v7a'
            abiFilters 'arm64-v8a'
        }

        externalNativeBuild {
            cmake {
                arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_shared', '-DTarget=Android'
            }
        }
    }

    externalNativeBuild {
        cmake {
            path '../../../../../../CMakeLists.txt'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    exec {
        workingDir '../../../../../../'
        def cmd = [
            'python', 'src/MrEngine/App/Platform/android/copy_assets.py'
        ]
        commandLine cmd
    }

    // for vulkan validation layer libs
    sourceSets {
        main {
            jniLibs {
                srcDir "${ndkDir}/sources/third_party/vulkan/src/build-android/jniLibs"
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}
