apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

apply from: "${rootProject.projectDir}/build-scripts/git-version-string.gradle"
apply from: "${rootProject.projectDir}/build-scripts/cmake-extra-args.gradle"

def ouinetVersionName = file('../../version.txt').text.trim()
def ouinetBuildId = gitVersionString

android {
    namespace "ie.equalit.ouinet"
    // Please read `doc/android-sdk-versions.md` and keep in sync with it.
    compileSdkVersion System.getenv('OUINET_TARGET_API').toInteger()
    defaultConfig {
        minSdkVersion System.getenv('OUINET_MIN_API').toInteger()
        targetSdkVersion System.getenv('OUINET_TARGET_API').toInteger()
        versionCode 1
        versionName ouinetVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                arguments "-DANDROID_STL='c++_shared'"
                cmakeExtraArguments.each { arg ->
                    arguments.add(arg)
                }
                cppFlags "-std=c++20 -frtti -fexceptions"
                targets "native-lib"
            }
        }

        ndkVersion "27.2.12479018"
        ndk {
          if (android_abi == "omni") {
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
          } else {
            abiFilters "$android_abi"
          }
        }
    }
    buildFeatures {
        buildConfig true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField("String", "BUILD_ID", "\"Release ${ouinetBuildId}\"")
        }
        debug {
            buildConfigField("String", "BUILD_ID", "\"Debug ${ouinetBuildId}\"")
        }
    }
    externalNativeBuild {
        cmake {
            version "3.18.0+"
            path "CMakeLists.txt"
            buildStagingDirectory (new File(project.buildDir, "../build-cmake"))
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
    lintOptions {
        disable 'UnsafeNativeCodeLocation' // Disable warning about obfsproxy executable in assets
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // Please read `doc/android-sdk-versions.md` and keep in sync with it.
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.getkeepsafe.relinker:relinker:1.4.4'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'
    testImplementation 'org.mockito:mockito-core:4.3.0'
    testImplementation 'org.mockito:mockito-inline:4.3.0'
    testImplementation 'org.mockito:mockito-junit-jupiter:4.3.0'
    testImplementation 'com.android.support.test:rules:1.0.2'
    testImplementation 'com.android.support:support-annotations:28.0.0'
    testImplementation 'com.android.support.test:runner:1.0.2'
    testImplementation 'org.assertj:assertj-core:3.11.1'
}

ext {
    PUBLISH_GROUP_ID = 'ie.equalit.ouinet'
    PUBLISH_VERSION = "${ouinetVersionName}"
    PUBLISH_ARTIFACT_ID = "ouinet-${android_abi}"
}

tasks.withType(Sign) {
    onlyIf { rootProject.gradle.startParameter.taskNames.contains('publishToSonatype') }
}

apply from: "${rootProject.projectDir}/build-scripts/publish-module.gradle"
