plugins {
    id 'com.android.application'
}

// 10,00,000 major-minor-build
def AppMajorVersion = 1
def AppMinorVersion = 0
def AppBuildNumber = 157

def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber

android {
    signingConfigs {
        debug {
            storeFile file('../sign.jks')
            storePassword 'XyMpApp'
            keyAlias 'xymp'
            keyPassword 'XyMpApp'
        }
    }
    namespace 'com.xypower.mpapp'
    compileSdk 33

    defaultConfig {
        applicationId "com.xypower.mpapp"
        minSdk COMPILE_MIN_SDK_VERSION as int
        //noinspection ExpiredTargetSdkVersion
        targetSdk 28
        versionCode AppVersionCode
        versionName AppVersionName

        buildConfigField "long","BUILD_TIMESTAMP", System.currentTimeMillis() + "L"

        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
        externalNativeBuild {
            cmake {
                // cppFlags '-std=c++17 -frtti -fexceptions -Wno-error=format-security'
                cppFlags '-std=c++17 -fexceptions -Wno-error=format-security'
                // cppFlags '-std=c++17 -Wno-error=format-security'
                // arguments "-DANDROID_STL=c++_shared"
                arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DASIO_ROOT=" + asioroot, "-DEVPP_ROOT=" + evpproot, "-DNCNN_ROOT=" + ncnnroot
                abiFilters 'arm64-v8a'
                // setAbiFilters(['arm64-v8a'])
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            jniDebuggable true
            testCoverageEnabled false
        }
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    externalNativeBuild {
        cmake {
            path file('src/main/cpp/CMakeLists.txt')
            version '3.22.1'
        }
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all { output ->
            if (outputFileName.endsWith('.apk')) {
                def buildTypeFlag = "dbg"
                if(variant.buildType.name.equals('release')) {
                    buildTypeFlag = "rel"
                }
                def fileName = "mpapp_v${defaultConfig.versionName}_${buildTypeFlag}_${new Date(System.currentTimeMillis()).format("yyyyMMdd")}.apk"
                outputFileName = fileName
            }
        }
    }

    buildFeatures {
        viewBinding true
    }

    ndkVersion '26.1.10909125'

    packagingOptions {
        exclude 'META-INF/INDEX.LIST'
        exclude 'META-INF/io.netty.versions.properties'
        exclude 'META-INF/DEPENDENCIES'
    }
}

dependencies {

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
    // implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.android.material:material:1.8.0'
    implementation project(path: ':common')
//    implementation 'androidx.camera:camera-video:1.2.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation 'com.googlecode.mp4parser:isoparser:1.1.21'
    // implementation 'com.tencent.mars:mars-core:1.2.5'
    // implementation 'com.tencent:mmkv-static:1.3.0'
    // implementation project(path: ':opencv')
    implementation files('libs/devapi.aar')
    debugImplementation files('libs/rtmp-client-debug.aar')
    releaseImplementation files('libs/rtmp-client.aar')
    implementation project(':gpuv')

//    implementation group: 'io.netty', name: 'netty-all', version: '4.1.96.Final'
//    implementation 'io.netty:netty-all:4.1.23.Final'
//    implementation 'org.apache.logging.log4j:log4j-api:2.14.0'
//    implementation 'org.apache.logging.log4j:log4j-core:2.14.0'
}