buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.2.2' // works with Qt 6.7+ // Java 17
    }
}

repositories {
    google()
    mavenCentral()
}

apply plugin: 'com.android.application'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.core:core:1.6.1'
}

def getTimestampStr() { return new Date().format('yyyyMMddHHmmss') }
def timestampInt = (int)(new Date().getTime() / 1000 / 1)

android {
    /*******************************************************
     * The following variables:
     * - androidBuildToolsVersion,
     * - androidCompileSdkVersion
     * - qtAndroidDir - holds the path to qt android files
     *                   needed to build any Qt application
     *                   on Android.
     *
     * are defined in gradle.properties file. This file is
     * updated by QtCreator and androiddeployqt tools.
     * Changing them manually might break the compilation!
     *******************************************************/

    compileSdkVersion androidCompileSdkVersion
    buildToolsVersion androidBuildToolsVersion
    ndkVersion androidNdkVersion

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = [qtAndroidDir + '/src', 'src', 'java']
            aidl.srcDirs = [qtAndroidDir + '/src', 'src', 'aidl']
            res.srcDirs = [qtAndroidDir + '/res', 'res']
            resources.srcDirs = ['resources']
            renderscript.srcDirs = ['src']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
    }

    tasks.withType(JavaCompile) {
        options.incremental = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    packagingOptions {
        jniLibs {
            useLegacyPackaging true
        }
    }

    lintOptions {
        abortOnError false
    }

    // Do not compress Qt binary resources file
    aaptOptions {
        noCompress 'rcc'
    }

    defaultConfig {
        resConfig "en"
        minSdkVersion 23 // qtMinSdkVersion
        targetSdkVersion 36 // qtTargetSdkVersion
        ndk.abiFilters = qtTargetAbiList.split(",")

        namespace 'com.emeric.watchflower'
        versionName "6.0"
        versionCode timestampInt
        manifestPlaceholders = [versionName: versionName, versionCode: versionCode]
    }

    packagingOptions {
        // generic
        exclude 'lib/*/*_qmltooling_*'
        exclude 'lib/*/*_Controls_Fusion_*'
        exclude 'lib/*/*_Controls_Imagine_*'
        exclude 'lib/*/*_Controls_Universal_*'
        // image formats
        exclude 'lib/*/*_imageformats_qgif_*'
        exclude 'lib/*/*_imageformats_qico_*'
        exclude 'lib/*/*_imageformats_qicns_*'
        exclude 'lib/*/*_imageformats_qjpeg_*'
        exclude 'lib/*/*_imageformats_qtga_*'
        exclude 'lib/*/*_imageformats_qtiff_*'
        exclude 'lib/*/*_imageformats_qwbmp_*'
        exclude 'lib/*/*_imageformats_qwebp_*'
        // multimedia backend
        exclude 'lib/*/*_multimedia_androidmediaplugin_*'
        exclude 'lib/*/*_multimedia_ffmpegmediaplugin_*'
    }
}
