apply plugin: 'com.android.application'

def props = new Properties()
File keystoreProperties = rootProject.file("keystore.properties")
if (keystoreProperties.exists()) {
    props.load(new FileInputStream(keystoreProperties))
} else {
    props['keystorefile'] = 'none';
}

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.2'

    applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${parent.name}-${variant.name}-${variant.versionName}.apk"
        }
    }

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.generateVersionCode(1)
        versionName rootProject.generateVersionName()
        vectorDrawables.useSupportLibrary = true
        buildConfigField "String", "LICENSE_KEY",  "$props.LICENSE_KEY"
        buildConfigField "String", "DROPBOX_CLIENT_ID",  "$props.DROPBOX_CLIENT_ID"
        buildConfigField "String", "DROPBOX_CLIENT_KEY",  "$props.DROPBOX_CLIENT_KEY"
        buildConfigField "String", "ONEDRIVE_CLIENT_ID",  "$props.ONEDRIVE_CLIENT_ID"
        buildConfigField "String", "ONEDRIVE_CLIENT_KEY",  "$props.ONEDRIVE_CLIENT_KEY"
        buildConfigField "String", "BOX_CLIENT_ID",  "$props.BOX_CLIENT_ID"
        buildConfigField "String", "BOX_CLIENT_KEY",  "$props.BOX_CLIENT_KEY"
        buildConfigField "String", "PLAYSTORE_LICENSE_KEY",  "$props.PLAYSTORE_LICENSE_KEY"
        buildConfigField "String", "MERCHANT_ID",  "$props.MERCHANT_ID"
    }
    signingConfigs {
        release
    }
    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                    'proguard-rules.pro'
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                    'proguard-rules.pro'
        }
    }
    flavorDimensions "release", "default"
    productFlavors {
        free {
            applicationId "dev.dworks.apps.anexplorer"
            dimension "default"
            buildConfigField "String", "GOOGLE_DRIVE_CLIENT_ID",  "$props.GOOGLE_DRIVE_CLIENT_ID"
        }
        pro {
            applicationId "dev.dworks.apps.anexplorer.pro"
            dimension "default"
            buildConfigField "String", "GOOGLE_DRIVE_CLIENT_ID",  "$props.GOOGLE_DRIVE_PRO_CLIENT_ID"
        }
        underground {
            applicationId "dev.dworks.apps.anexplorer.underground"
            dimension "default"
            buildConfigField "String", "GOOGLE_DRIVE_CLIENT_ID",  "$props.GOOGLE_DRIVE_PRO_CLIENT_ID"
        }
        wear {
            dimension "default"
            minSdkVersion 23
            versionCode rootProject.generateVersionCode(2)
            buildConfigField "String", "GOOGLE_DRIVE_CLIENT_ID",  "$props.GOOGLE_DRIVE_PRO_CLIENT_ID"
        }
        google {
            dimension "release"
        }
        amazon {
            dimension "release"
            targetSdkVersion 25
        }
        other {
            dimension "release"
        }
        paid {
            applicationId "dev.dworks.apps.anexplorer.pro"
            dimension "release"
        }
    }
    variantFilter { variant ->
        def names = variant.flavors*.name

        if ((names.contains("underground") && (names.contains("google") || names.contains("other")))
            || names.contains("paid") && !names.contains("wear")) {
            variant.ignore = true
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.jaredrummler:android-processes:1.1.1'
    implementation 'com.github.mjdev:libaums:0.5.5'
    implementation 'org.apache.ftpserver:ftpserver-core:1.1.1'
    implementation 'commons-net:commons-net:3.6'
    implementation 'com.zsoltsafrany:needle:1.0.0'
    implementation 'com.cloudrail:cloudrail-si-android:2.22.4'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'com.github.javiersantos:AppUpdater:2.6.5'
    freeImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
    freeImplementation "com.google.firebase:firebase-core:16.0.3"
    freeImplementation "com.google.firebase:firebase-ads:15.0.1"
    freeImplementation 'com.anjlab.android.iab.v3:library:1.0.44'

    wearImplementation 'com.google.android.support:wearable:2.3.0'
    wearImplementation 'com.google.android.gms:play-services-wearable:16.0.0'
    wearImplementation 'androidx.preference:preference:1.0.0'
    wearImplementation 'androidx.wear:wear:1.0.0'
    wearImplementation 'androidx.preference:preference:1.0.0'
    wearCompileOnly 'com.google.android.wearable:wearable:2.3.0'
}

android.signingConfigs.release.storeFile rootProject.file(props.keyStore)
android.signingConfigs.release.storePassword props.keyStorePassword
android.signingConfigs.release.keyAlias props.keyAlias
android.signingConfigs.release.keyPassword props.keyAliasPassword

if (getGradle().getStartParameter().getTaskRequests().toString().contains("Free")) {
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'io.fabric'
}
