buildscript {
    ext {
        kotlin_version = '1.4.10'
    }
    ext.buildConfig = [
        'compileSdkVersion': 30,
        'minSdkVersion': 21,
        'targetSdkVersion': 30
    ]
    ext.versions = [
        'kotlin': "$kotlin_version",
        'coroutines': '1.3.5',
        'junit': '4.12'
    ]
    repositories {
        google()
        jcenter()
        maven {
            url 'https://jitpack.io'
        }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
        classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3'
    }
}

apply plugin: 'maven-publish'
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-allopen'
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'

repositories {

    google()
    jcenter()
    maven {
        url 'https://jitpack.io'
    }
}

android {
    compileSdkVersion buildConfig.compileSdkVersion

    useLibrary 'android.test.runner'

    ndkVersion "21.3.6528147"

    defaultConfig {
        minSdkVersion buildConfig.minSdkVersion
        targetSdkVersion buildConfig.targetSdkVersion
        versionCode = 1_00_00
        versionName = "1.0.0"
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments clearPackageData: 'true'
        multiDexEnabled true
        archivesBaseName = "ergo-lib-$versionName"
    }

    buildTypes {
        debug {
            // for test builds, which exceed the dex limit because they pull in things like mockito and grpc-testing
            multiDexEnabled true
            minifyEnabled false
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
        }
        release {
            multiDexEnabled false
            minifyEnabled false
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
        }
    }
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    testOptions {
        unitTests.all {
            testLogging {
                showStandardStreams = true
            }
        }

        unitTests {
            includeAndroidResources = true
        }
    }
}

cargo {
    module = "."
    libname = "ergowalletlibjni"
    targets = [
        "arm",
        "arm64",
        "x86",
        "x86_64",
    ]
    profile = "release"
    prebuiltToolchains = true
    // Where Cargo writes its outputs.
    targetDirectory = '../../target'
}

tasks.whenTaskAdded { task ->
    if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) {
        task.dependsOn 'cargoBuild'
    }
}


dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'

    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutines}"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.coroutines}"

    // Tests
    testImplementation 'androidx.multidex:multidex:2.0.1'
    testImplementation "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
    testImplementation "junit:junit:${versions.junit}"

    androidTestImplementation "androidx.test:runner:1.2.0"
    androidTestImplementation "androidx.test:core:1.2.0"
    androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test:runner:1.2.0'
}


