apply plugin: 'com.android.application'

android {
    compileSdkVersion project.ext.mycompileSdkVersion
    buildToolsVersion project.ext.mybuildToolsVersion

    defaultConfig {
        applicationId project.ext.myApplicationId
        minSdkVersion project.ext.myminSdkVersion
        targetSdkVersion project.ext.mytargetSdkVersion
        versionCode project.ext.myVersionCode
        versionName project.ext.myVersionName
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    sourceSets {
        main {
            def nDir = new File(buildDir, 'native-libs')
            project.logger.lifecycle('Native src dir: ' + nDir)
            jniLibs.srcDir nDir
        }
    }
    signingConfigs {
        config {
            Properties props = new Properties()
            def propFile = new File('geopaparazzi.app/ant.properties')
            if (propFile.canRead()) {
                props.load(new FileInputStream(propFile))
                if (props != null && props.containsKey('key.store') && props.containsKey('key.store.password') &&
                        props.containsKey('key.alias') && props.containsKey('key.alias.password')) {
                    storeFile = file(props['key.store'])
                    storePassword = props['key.store.password']
                    keyAlias = props['key.alias']
                    keyPassword = props['key.alias.password']
                } else {
                    println 'geopaparazzi.app/ant.properties found but some entries are missing'
                    android.buildTypes.release.signingConfig = null
                }
            } else {
                println 'geopaparazzi.app/ant.properties not found'
                android.buildTypes.release.signingConfig = null
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            signingConfig signingConfigs.config
            //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    output.outputFileName = "GeoPaparazzi_" + android.defaultConfig.versionName + ".apk"
                }
            }
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
        disable 'GoogleAppIndexingWarning'
    }
    compileOptions {
        encoding = 'UTF-8'
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


task copyNativeLibs(type: Copy) {
    from(new File(project(':geopaparazzi_map').projectDir, 'jniLibs')) {
        include 'arm64-v8a/libjsqlite.so'
        include 'armeabi-v7a/libjsqlite.so'
        include 'x86_64/libjsqlite.so'
    }
    into new File(buildDir, 'native-libs')
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'


dependencies {
    api 'com.android.support:appcompat-v7:28.0.0'

    implementation project(':geopaparazzi_core')
    implementation project(':geopaparazzi_default_export_plugins')
    implementation project(':geopaparazzi_default_import_plugins')
    implementation project(':geopaparazzi_pdf_export_plugins')
    implementation project(':geopaparazzi_profiles_export_plugins')
    implementation project(':geopaparazzi_profiles_import_plugins')
    implementation project(':geopaparazzi_projects_export_plugins')
    implementation project(':geopaparazzi_projects_import_plugins')
}
