apply plugin: 'com.android.application'

android {
    namespace = "com.logship.mobile"
    compileSdk = rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "com.logship.mobile"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 38
        versionName "1.0.37"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        aaptOptions {
             // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
             // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
            ignoreAssetsPattern = '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
        }
    }
    // Release signing is configured only when the keystore env vars are present, so that
    // `assembleDebug` and unsigned builds keep working with no keystore in the repo.
    // For a distributable in-app-update APK, the SAME key that signed the previously
    // installed APK must be used, or the sideload update fails with
    // INSTALL_FAILED_UPDATE_INCOMPATIBLE. Provide via:
    //   LOGSHIP_KEYSTORE, LOGSHIP_STORE_PASSWORD, LOGSHIP_KEY_ALIAS, LOGSHIP_KEY_PASSWORD
    signingConfigs {
        release {
            def ksPath = System.getenv('LOGSHIP_KEYSTORE')
            if (ksPath) {
                storeFile file(ksPath)
                storePassword System.getenv('LOGSHIP_STORE_PASSWORD')
                keyAlias System.getenv('LOGSHIP_KEY_ALIAS') ?: 'logship'
                keyPassword System.getenv('LOGSHIP_KEY_PASSWORD')
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (System.getenv('LOGSHIP_KEYSTORE')) {
                signingConfig signingConfigs.release
            }
        }
    }
}

repositories {
    flatDir{
        dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
    implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
    implementation project(':capacitor-android')
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
    implementation project(':capacitor-cordova-android-plugins')
}

apply from: 'capacitor.build.gradle'

try {
    def servicesJSON = file('google-services.json')
    if (servicesJSON.text) {
        apply plugin: 'com.google.gms.google-services'
    }
} catch(Exception e) {
    logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
