buildscript {
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:8.1.3"
    }
}

repositories {
    mavenCentral()
    google()
}

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

android {
    compileSdk = 34
    buildToolsVersion = '34.0.0'
    ndkVersion '25.2.9519653'
    namespace "uk.co.adventuregamestudio.runtime"

    defaultConfig {
        if (buildAsApplication) {
            applicationId "uk.co.adventuregamestudio.runtime"
        }
        minSdkVersion 19
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        
        externalNativeBuild {
            cmake {
                 arguments "-DANDROID_APP_PLATFORM=android-16", "-DANDROID_STL=c++_static"
                abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
                //   abiFilters'arm64-v8a'
             //   abiFilters 'arm64-v8a', 'x86', 'x86_64'
             }
        }
    }

    buildTypes {
        debug {
            ext.alwaysUpdateBuildId = false
            crunchPngs false
            debuggable true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    // maybe this should be a variable set somewhere but testing for this works
    if (file("./libs/arm64-v8a/libengine.so").exists()) {
        sourceSets.main {
            jniLibs.srcDir 'libs'
        }
    } else {
        externalNativeBuild {
            cmake {
                version "3.22.1+"  // SET HERE YOUR CMAKE SYSTEM VERSION, must be above 3.19.1
                path '../../../CMakeLists.txt'
            }
        }
    }

    lintOptions {
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    
    if (buildAsLibrary) {
        libraryVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "uk.co.adventuregamestudio.runtime.aar"
            }
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.preference:preference:1.2.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
