buildscript {
    ext {
        kotlin_version = '1.9.0'
    }
    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:8.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
        classpath 'org.mozilla.rust-android-gradle:plugin:0.9.2'
    }
}

apply plugin: 'maven-publish'
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
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 "26.2.11394342"
    android {
        namespace 'com.ergoplatform'
    }

    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_18
        targetCompatibility JavaVersion.VERSION_18
    }
    kotlinOptions {
        jvmTarget = "18"
    }

    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'
}
