apply plugin: 'com.android.application'
apply from: 'nonnull.gradle'

// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
final def keystorePropertiesFile = rootProject.file("keystore.properties")

android {
    buildToolsVersion '29.0.2'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    compileSdkVersion 29
    dataBinding.enabled true
    defaultConfig {
        applicationId 'com.wireguard.android'
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 464
        versionName '0.0.20200206'
        buildConfigField 'int', 'MIN_SDK_VERSION', "$minSdkVersion.apiLevel"
    }
    // If the keystore file exists
    if (keystorePropertiesFile.exists()) {
        // Initialize a new Properties() object called keystoreProperties.
        final def keystoreProperties = new Properties()

        // Load your keystore.properties file into the keystoreProperties object.
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

        signingConfigs {
            release {
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile file(keystoreProperties['storeFile'])
                storePassword keystoreProperties['storePassword']
            }
        }
    }
    buildTypes {
        release {
            if (keystorePropertiesFile.exists()) signingConfig signingConfigs.release
            externalNativeBuild {
                cmake {
                    arguments "-DANDROID_PACKAGE_NAME=${android.defaultConfig.applicationId}"
                }
            }
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
            externalNativeBuild {
                cmake {
                    arguments "-DANDROID_PACKAGE_NAME=${android.defaultConfig.applicationId}${applicationIdSuffix}"
                }
            }
        }
    }
    externalNativeBuild {
        cmake {
            path 'tools/CMakeLists.txt'
        }
    }
}

ext {
    annotationsVersion = '1.1.0'
    appcompatVersion = '1.1.0'
    cardviewVersion = '1.0.0'
    databindingVersion = '3.5.3'
    materialComponentsVersion = '1.1.0'
    jsr305Version = '3.0.2'
    preferenceVersion = '1.1.0'
    streamsupportVersion = '1.7.1'
    threetenabpVersion = '1.2.2'
    // ZXING switched minSdk to 24 so we cannot upgrade to 4.0.2 without following suit.
    // If you choose to upgrade to minSDK 24 then you should also disable Jetifier from
    // gradle.properties.
    zxingEmbeddedVersion = '3.6.0'
    eddsaVersion = '0.3.0'
}

dependencies {
    implementation "androidx.annotation:annotation:$annotationsVersion"
    implementation "androidx.appcompat:appcompat:$appcompatVersion"
    implementation "androidx.cardview:cardview:$cardviewVersion"
    implementation "androidx.databinding:databinding-runtime:$databindingVersion"
    implementation "androidx.preference:preference:$preferenceVersion"
    implementation "com.google.android.material:material:$materialComponentsVersion"
    implementation "com.google.code.findbugs:jsr305:$jsr305Version"
    implementation "com.jakewharton.threetenabp:threetenabp:$threetenabpVersion"
    implementation "com.journeyapps:zxing-android-embedded:$zxingEmbeddedVersion"
    implementation "net.sourceforge.streamsupport:android-retrofuture:$streamsupportVersion"
    implementation "net.sourceforge.streamsupport:android-retrostreams:$streamsupportVersion"
    implementation "net.i2p.crypto:eddsa:$eddsaVersion"
}

tasks.withType(JavaCompile) {
    options.compilerArgs << '-Xlint:unchecked'
    options.deprecation = true
}