apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlinx-serialization'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.github.triplet.play'
apply plugin: 'de.mobilej.unmock'
// apply plugin: "app.brant.amazonappstorepublisher"

// Apply the Crashlytics Gradle plugin
apply plugin: 'com.google.firebase.crashlytics'

// protobuf
apply plugin: 'com.google.protobuf'

apply plugin: 'kotlin-kapt'

unMock {
    keep "android.net.Uri"
    keep "android.util.Base64"
}

android {
    /*
    signingConfigs {
        release {
            storeFile "$meshtasticKeystoreFile"
            keyAlias 'upload'
            storePassword "$meshtasticKeystorePassword"
            keyPassword "$meshtasticKeyPassword"
        }
    } */
    compileSdkVersion 29
    // leave undefined to use version plugin wants
    // buildToolsVersion "30.0.2" // Note: 30.0.2 doesn't yet work on Github actions CI
    defaultConfig {
        applicationId "com.geeksville.mesh"
        minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works)
        targetSdkVersion 29
        versionCode 20211 // format is Mmmss (where M is 1+the numeric major number
        versionName "1.2.11"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        // per https://developer.android.com/studio/write/vector-asset-studio
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            pseudoLocalesEnabled true
        }
    }

    defaultConfig {
        // We have to list all translated languages here, because some of our libs have bogus languages that google play
        // doesn't like and we need to strip them (gr)
        resConfigs "cs", "de", "el", "en", "es", "fi", "fr", "ga", "ht", "it", "ja", "ko", "nl", "no", "pt", "ro", "ru", "sk", "sl", "sq", "sv", "tr", "zh"

        // Needed to make mapbox work inside the firebase testlab - FIXME, alas, still doesn't work
        ndk {
            // abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
    }

    buildFeatures {
        viewBinding true
    }

    // Set both the Java and Kotlin compilers to target Java 8.

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    lintOptions {
        abortOnError false
    }
}

play {
    // configure per https://github.com/Triple-T/gradle-play-publisher#authenticating-gradle-play-publisher
    track = 'internal'
    defaultToAppBundles = true
    serviceAccountCredentials = file("../../play-credentials.json")
}

// per protobuf-gradle-plugin docs, this is recommended for android
protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.15.3'
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    // turned off for now so I can use json printing in debug panel
                    // use the smaller android version of the library
                    //option "lite"
                }
            }
        }
    }
}

dependencies {

    def room_version = '2.2.6'

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.fragment:fragment-ktx:1.3.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.viewpager2:viewpager2:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0'
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"


    // optional - Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:$room_version"

    // optional - Test helpers
    testImplementation "androidx.room:room-testing:$room_version"
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    // kotlin serialization
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc"

    // rate this app
    implementation "com.vorlonsoft:androidrate:1.2.1"

    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

    // For now I'm not using javalite, because I want JSON printing
    implementation ('com.google.protobuf:protobuf-java:3.15.5')

    // For UART access
    // implementation 'com.google.android.things:androidthings:1.0'
    implementation 'com.github.mik3y:usb-serial-for-android:v3.0.0'

    // mapbox
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.0'

    // mapbox specifies a really old version of okhttp3 which causes lots of API warnings.  trying a newer version
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'

    // location services
    implementation 'com.google.android.gms:play-services-location:18.0.0'

    // For Google Sign-In (owner name accesss)
    implementation 'com.google.android.gms:play-services-auth:19.0.0'

    // Add the Firebase SDK for Crashlytics.
    implementation 'com.google.firebase:firebase-crashlytics:17.3.1'

    // alas implementation bug deep in the bowels when I tried it for my SyncBluetoothDevice class
    // implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3"

    // add SDKs for any other desired Firebase products
    // https://firebase.google.com/docs/android/setup#available-libraries

    // barcode support
    // per https://github.com/journeyapps/zxing-android-embedded for support of android version 22
    implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false }
    implementation 'com.google.zxing:core:3.4.1'

    def work_version = '2.5.0'

    // Work Request - used to delay boot event handling
    // implementation "androidx.work:work-runtime:$work_version"
    implementation "androidx.work:work-runtime-ktx:$work_version"

    implementation project(':geeksville-androidlib')
}
