/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

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

android {
    compileSdkVersion config.compileSdkVersion

    defaultConfig {
        minSdkVersion config.minSdkVersion
        targetSdkVersion config.targetSdkVersion
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

configurations {
    // There's an interaction between Gradle's resolution of dependencies with different types
    // (@jar, @aar) for `implementation` and `testImplementation` and with Android Studio's built-in
    // JUnit test runner.  The runtime classpath in the built-in JUnit test runner gets the
    // dependency from the `implementation`, which is type @aar, and therefore the JNA dependency
    // doesn't provide the JNI dispatch libraries in the correct Java resource directories.  I think
    // what's happening is that @aar type in `implementation` resolves to the @jar type in
    // `testImplementation`, and that it wins the dependency resolution battle.
    //
    // A workaround is to add a new configuration which depends on the @jar type and to reference
    // the underlying JAR file directly in `testImplementation`.  This JAR file doesn't resolve to
    // the @aar type in `implementation`.  This works when invoked via `gradle`, but also sets the
    // correct runtime classpath when invoked with Android Studio's built-in JUnit test runner.
    // Success!
    jnaForTest
}

// Define library names and version constants.
String GLEAN_LIBRARY = "org.mozilla.telemetry:glean:${Versions.mozilla_glean}"
String GLEAN_LIBRARY_FORUNITTESTS = "org.mozilla.telemetry:glean-native-forUnitTests:${Versions.mozilla_glean}"

dependencies {
    implementation Dependencies.kotlin_stdlib
    implementation Dependencies.kotlin_coroutines
    implementation Dependencies.androidx_work_runtime
    
    api GLEAN_LIBRARY

    // So consumers can set a HTTP client.
    api project(':concept-fetch')

    implementation project(':support-ktx')
    implementation project(':support-base')
    implementation project(':support-utils')

    testImplementation Dependencies.androidx_test_core

    testImplementation Dependencies.testing_junit
    testImplementation Dependencies.testing_robolectric
    testImplementation Dependencies.testing_mockito
    testImplementation Dependencies.testing_mockwebserver
    testImplementation Dependencies.androidx_work_testing

    testImplementation project(':support-test')
    testImplementation project(':lib-fetch-httpurlconnection')
    testImplementation project(':lib-fetch-okhttp')

    testImplementation GLEAN_LIBRARY_FORUNITTESTS
}

apply from: '../../../publish.gradle'
ext.configurePublish(config.componentsGroupId, archivesBaseName, project.ext.description)
