apply plugin: 'org.greenrobot.greendao'
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'de.mannodermaus.android-junit5'

android {
	defaultPublishConfig "debug"

	def globalConfiguration = rootProject.extensions.getByName("ext")

	compileSdkVersion globalConfiguration["androidCompileSdkVersion"]
	buildToolsVersion globalConfiguration["androidBuildToolsVersion"]

	defaultConfig {
		minSdkVersion globalConfiguration["androidMinSdkVersion"]
		targetSdkVersion globalConfiguration["androidTargetSdkVersion"]

		buildConfigField 'int', 'VERSION_CODE', "${globalConfiguration["androidVersionCode"]}"
		buildConfigField "String", "VERSION_NAME", "\"${globalConfiguration["androidVersionName"]}\""
	}

	compileOptions {
		sourceCompatibility JavaVersion.VERSION_1_8
		targetCompatibility JavaVersion.VERSION_1_8
	}

	lintOptions {
		quiet true
		abortOnError false
		ignoreWarnings true
	}

	buildTypes {
		release {
			buildConfigField "String", "ONEDRIVE_API_KEY", "\"" + getApiKey('ONEDRIVE_API_KEY') + "\""
			buildConfigField "String", "ONEDRIVE_API_REDIRCT_URI", "\"" + getApiKey('ONEDRIVE_API_REDIRCT_URI') + "\""
		}

		debug {
			buildConfigField "String", "ONEDRIVE_API_KEY", "\"" + getApiKey('ONEDRIVE_API_KEY_DEBUG') + "\""
			buildConfigField "String", "ONEDRIVE_API_REDIRCT_URI", "\"" + getApiKey('ONEDRIVE_API_REDIRCT_URI_DEBUG') + "\""
		}
	}

	flavorDimensions "version"

	productFlavors {
		playstore {
			dimension "version"
		}

		apkstore {
			dimension "version"
		}

		fdroid {
			dimension "version"
		}
	}

	sourceSets {
		playstore {
			java.srcDirs = ['src/main/java', 'src/main/java/', 'src/notFoss/java', 'src/notFoss/java/']
		}

		apkstore {
			java.srcDirs = ['src/main/java', 'src/main/java/', 'src/notFoss/java', 'src/notFoss/java/']
		}

		fdroid {
			java.srcDirs = ['src/main/java', 'src/main/java/', 'src/foss/java', 'src/foss/java/']
		}
	}
}

greendao {
	schemaVersion 4
}

configurations.all {
	// Check for updates every build (use for cryptolib snapshot)
	//resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

dependencies {
	def dependencies = rootProject.ext.dependencies

	implementation project(':domain')
	implementation project(':util')
	implementation project(':msa-auth-for-android')

	// cryptomator
	implementation dependencies.cryptolib

	// greendao
	api dependencies.greenDao
	// dagger
	annotationProcessor dependencies.daggerCompiler
	implementation dependencies.dagger
	// cloud
	implementation dependencies.dropbox
	implementation dependencies.msgraph

	playstoreImplementation dependencies.googlePlayServicesAuth
	apkstoreImplementation dependencies.googlePlayServicesAuth

	playstoreImplementation(dependencies.googleApiServicesDrive) {
		exclude module: 'guava-jdk5'
		exclude module: 'httpclient'
	}
	apkstoreImplementation(dependencies.googleApiServicesDrive) {
		exclude module: 'guava-jdk5'
		exclude module: 'httpclient'
	}

	playstoreImplementation(dependencies.googleApiClientAndroid) {
		exclude module: 'guava-jdk5'
		exclude module: 'httpclient'
	}
	apkstoreImplementation(dependencies.googleApiClientAndroid) {
		exclude module: 'guava-jdk5'
		exclude module: 'httpclient'
	}

	// rest
	implementation dependencies.rxJava
	implementation dependencies.rxAndroid
	implementation dependencies.okHttp
	implementation dependencies.okHttpDigest
	implementation dependencies.androidAnnotations
	compileOnly dependencies.javaxAnnotation
	implementation dependencies.gson

	implementation dependencies.commonsCodec

	implementation dependencies.documentFile

	implementation dependencies.lruFileCache

	implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

	// test
	testImplementation dependencies.junit
	testImplementation dependencies.junitApi
	testRuntimeOnly dependencies.junitEngine
	testImplementation dependencies.junitParams

	testImplementation dependencies.junit4
	testRuntimeOnly dependencies.junit4Engine

	testImplementation dependencies.mockito
	testImplementation dependencies.hamcrest
}

configurations {
	all*.exclude group: 'com.google.android', module: 'android'
}

static def getApiKey(key) {
	return System.getenv().getOrDefault(key, "")
}
