def buildAsLibrary = project.hasProperty('BUILD_AS_LIBRARY');
def buildAsApplication = !buildAsLibrary
if (buildAsApplication) {
    apply plugin: 'com.android.application'
}
else {
    apply plugin: 'com.android.library'
}

android.ndkVersion '27.2.12479018'

android {
    if (buildAsApplication) {
        namespace "org.s25rttr.sdl"
    }
    packagingOptions {
        jniLibs {
            useLegacyPackaging = true
        }
    }
    compileSdkVersion 34
    defaultConfig {
    applicationId "org.s25rttr.sdl"
    archivesBaseName = "s25rttr"
        minSdkVersion 28
        targetSdkVersion 34
        versionCode 11 // incremented each release
        versionName "0.1.4"
        externalNativeBuild {
            //ndkBuild {
            //    arguments "APP_PLATFORM=android-19"
            //    abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
            //}
             cmake {
                 arguments "-DANDROID_APP_PLATFORM=android-28", "-DANDROID_STL=c++_shared"//, "--debug-output"//, "-DCMAKE_BUILD_TYPE=Debug"//, "-DCMAKE_PREFIX_PATH="
                 abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
                 abiFilters 'arm64-v8a'
             }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    applicationVariants.all { variant ->
        tasks["merge${variant.name.capitalize()}Assets"]
            .dependsOn("externalNativeBuild${variant.name.capitalize()}")
    }
    if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {
        sourceSets.main {
            jniLibs.srcDir 'libs'
        }
        externalNativeBuild {
            //ndkBuild {
            //    path 'jni/Android.mk'
            //}
             cmake {
                 path 'jni/CMakeLists.txt'
             }
        }
       
    }
    lint {
        abortOnError false
    }

    if (buildAsLibrary) {
        libraryVariants.all { variant ->
            variant.outputs.each { output ->
                def outputFile = output.outputFile
                if (outputFile != null && outputFile.name.endsWith(".aar")) {
                    def fileName = "org.s25rttr.sdl.aar";
                    output.outputFile = new File(outputFile.parent, fileName);
                }
            }
        }
    }
    
    signingConfigs {

   release {
       storeFile file(RELEASE_STORE_FILE)
       storePassword RELEASE_STORE_PASSWORD
       keyAlias RELEASE_KEY_ALIAS
       keyPassword RELEASE_KEY_PASSWORD

       // Optional, specify signing versions used
       v1SigningEnabled true
       v2SigningEnabled true
   }
}

buildTypes {
        release {
            signingConfig signingConfigs.release
        }
}
    
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.3.1' // or the latest version
    implementation 'androidx.core:core-ktx:1.6.0' // or the latest version
}
