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

android {
    if (buildAsApplication) {
        namespace "org.libsdl.app"
    }
    compileSdkVersion 34
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 34
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            /*ndkBuild {
                arguments "APP_PLATFORM=android-19"
                abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
            }*/
             cmake {
                 arguments "-DANDROID_APP_PLATFORM=android-19", "-DANDROID_STL=c++_static"
                 cppFlags "-std=c++11 -frtti -fexceptions"
                 abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
             }
        }
    }
    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'
                 version '3.22.1'
             }
        }
       
    }
    lint {
        abortOnError false
    }

    if (buildAsLibrary) {
        libraryVariants.all { variant ->
            variant.outputs.all { output ->
                if (output.outputFileName != null && output.outputFileName.endsWith(".aar")) {
                    output.outputFileName = "org.libsdl.app.aar"
                }
            }
        }
    }
}

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