plugins {
    id 'conventions.common'
    id 'conventions.boringssl'
    id 'conventions.android'
}

description = 'Conscrypt: Android Platform'

ext {
    androidHome = "$System.env.ANDROID_HOME"
    androidSdkInstalled = file("$androidHome").exists()
    androidVersionCode = 1
    androidVersionName = "$version"
    // Platform is always built against head, so we can use newer API versions.
    androidMinSdkVersion = 26
    androidTargetSdkVersion = 26
}

android {
    namespace "org.conscrypt"
    compileSdkVersion androidTargetSdkVersion

    compileOptions {
        sourceCompatibility androidMinJavaVersion;
        targetCompatibility androidMinJavaVersion
    }

    defaultConfig {
        minSdkVersion androidMinSdkVersion
        targetSdkVersion androidTargetSdkVersion
        versionCode androidVersionCode
        versionName androidVersionName

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        consumerProguardFiles 'proguard-rules.pro'

        externalNativeBuild {
            cmake {
                arguments '-DANDROID=True',
                        '-DANDROID_STL=c++_static',
                        "-DBORINGSSL_HOME=$boringsslHome"
                cFlags '-fvisibility=hidden',
                        '-DBORINGSSL_SHARED_LIBRARY',
                        '-DBORINGSSL_IMPLEMENTATION',
                        '-DOPENSSL_SMALL',
                        '-D_XOPEN_SOURCE=700',
                        '-Wno-unused-parameter'
            }
        }
        ndk {
            abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            java {
                srcDirs = [
                        "${rootDir}/common/src/main/java",
                        "src/main/java",
                ]
                excludes = [ 'org/conscrypt/Platform.java' ]
            }
        }
    }
    lintOptions {
        lintConfig file('lint.xml')
    }
}

configurations {
    publicApiDocs
}

dependencies {
    implementation project(path: ':conscrypt-openjdk', configuration: 'platform')
    publicApiDocs project(':conscrypt-api-doclet')
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', {
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'recyclerview-v7'
        exclude module: 'appcompat-v7'
        exclude module: 'design'
    })
    testCompileOnly project(':conscrypt-android-stub'),
                    project(':conscrypt-libcore-stub')
    testImplementation project(path: ":conscrypt-testing", configuration: "shadow"),
                       libs.junit
    compileOnly project(':conscrypt-android-stub'),
                project(':conscrypt-libcore-stub')

    // Adds the constants module as a dependency so that we can include its generated source
    compileOnly project(':conscrypt-constants')
}

// Disable running the tests.
tasks.withType(Test).configureEach {
    enabled = false
}
