plugins {
    id 'com.android.application'
}

def getVersionName = { ->
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'describe', '--tags', '--always'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

def getSentryUrl = { ->
	def url = System.env.SENTRY_UPLOAD_URL
	return url == null ? "" : url
}

android {
    namespace 'com.reicast.emulator'
    ndkVersion '23.2.8568313'
    compileSdk 29

    defaultConfig {
        applicationId "com.flycast.emulator"
        minSdk 16
        //noinspection ExpiredTargetSdkVersion
        targetSdk 29
        versionCode 8
        versionName getVersionName()
        vectorDrawables.useSupportLibrary = true

        externalNativeBuild {
            cmake {
                arguments "-DANDROID_ARM_MODE=arm", "-DSENTRY_UPLOAD_URL=" + getSentryUrl()
            }
        }

        ndk {
            moduleName 'flycast'
        }
        lintOptions {
            // avoid Error: Google Play requires that apps target API level 31 or higher.
            abortOnError false
        }
    }

    signingConfigs {
        debug {
            storeFile file("../debug.keystore")
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    externalNativeBuild {
        cmake {
            path file('../../../CMakeLists.txt')
            version '3.22.1'
        }
    }
    packagingOptions {
        resources {
            excludes += ['META-INF/DEPENDENCIES']
        }
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'org.apache.httpcomponents.client5:httpclient5:5.0.3'
    implementation 'org.slf4j:slf4j-android:1.7.35'
    implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
    implementation 'androidx.documentfile:documentfile:1.0.1'
}
