apply plugin: 'com.android.application' //or apply plugin: 'java'

dependencies {
    // Android dependencies.
    implementation rootProject.ext.supportV4
    implementation rootProject.ext.supportV7
    implementation rootProject.ext.supportDesign
    implementation rootProject.ext.supportCardview
    implementation rootProject.ext.supportRecyclerview
    implementation rootProject.ext.supportConstraintLayout
    implementation rootProject.ext.androidRoom
    implementation rootProject.ext.androidRoomRxJava
    annotationProcessor rootProject.ext.supportRoom

    implementation rootProject.ext.supportLifecycleExtension
    implementation rootProject.ext.supportLifecycleRuntime
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation rootProject.ext.androidxPreference
    annotationProcessor rootProject.ext.supportLifecycleCompiler

    // Dependency injection, view injection, event bus ...
    implementation rootProject.ext.dagger
    implementation rootProject.ext.otto
    implementation rootProject.ext.butterKnife
    annotationProcessor rootProject.ext.daggerCompiler
    annotationProcessor rootProject.ext.butterknifeCompiler

    // Google dependencies
    implementation rootProject.ext.gson
    implementation rootProject.ext.playServicesLocation
    implementation rootProject.ext.findBugs
    implementation rootProject.ext.playCore

    // RxJava for Android
    implementation rootProject.ext.rxAndroid
    implementation rootProject.ext.rxJava
    implementation rootProject.ext.rxPreferences
//    implementation rootProject.ext.rxBinding

    // other third party libraries
    implementation rootProject.ext.acra
    implementation rootProject.ext.helloCharts
    implementation rootProject.ext.fabProgressCircle
    implementation rootProject.ext.segmentedUIController
    implementation rootProject.ext.materialDialogs
    implementation "com.andkulikov:transitionseverywhere:2.1.0"
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation 'pub.devrel:easypermissions:3.0.0'

    // RxBindings
    implementation rootProject.ext.rxBindingCore
    implementation rootProject.ext.rxBindingAppCompat

    //MapBox SDK
    implementation (rootProject.ext.mapbox){
        exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-accounts'
    }

    // Test
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.mockito:mockito-core:3.11.0'
    testImplementation('org.powermock:powermock-api-mockito:1.7.4') {
        exclude module: 'hamcrest-core'
        exclude module: 'objenesis'
    }
    testImplementation('org.powermock:powermock-module-junit4:2.0.9') {
        exclude module: 'hamcrest-core'
        exclude module: 'objenesis'
    }
    androidTestImplementation 'junit:junit:4.13.2'
    androidTestImplementation('androidx.test:runner:1.4.0-beta02') {
        exclude module: 'support-annotations'
    }

    androidTestImplementation'android.arch.core:core-testing:1.1.0'
    androidTestImplementation('androidx.test:rules:1.4.0-beta02') {
        exclude module: 'support-annotations'
    }

    // modules
    api project(path: ':org.envirocar.core')
    api project(path: ':org.envirocar.remote')
    api project(path: ':org.envirocar.obd')
    api project(path: ':org.envirocar.storage')
    api project(path: ':org.envirocar.algorithm')
    implementation 'com.github.enviroCar:enviroCar-aidl:d67cfa49f3'
}


configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == "androidx") {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "${targetSdk}.+"
            }
        }
    }
}

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    ndkVersion rootProject.ext.ndkVersion

    signingConfigs {
        release {
            storeFile file(project.properties['RELEASE_STORE_FILE'] ?: "/tmp/tmp.key")
            storePassword project.properties['RELEASE_STORE_PASSWORD'] ?: ""
            keyAlias project.properties['RELEASE_KEY_ALIAS'] ?: ""
            keyPassword project.properties['RELEASE_KEY_PASSWORD'] ?: ""
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
            signingConfig signingConfigs.release
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
            signingConfig signingConfigs.debug
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        test.setRoot('tests/unit')
        androidTest.setRoot('tests/android')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    testOptions {
        unitTests {
            returnDefaultValues = true
        }
    }

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/rxjava.properties'
    }

    defaultConfig {
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        multiDexEnabled true
    }
}

// custom licenseFormat-tasks to access the directories, which are not part of the standard maven directory pattern
task licenseFormatSrc(type: com.hierynomus.gradle.license.tasks.LicenseFormat) {
    source = fileTree(dir: "src").include("**/*.java", '**/*.xml', '**/*.html').exclude('**/MoreObjects.java', '**/Preconditions.java')
}
licenseFormat.dependsOn licenseFormatSrc

task licenseFormatTests(type: com.hierynomus.gradle.license.tasks.LicenseFormat) {
    source = fileTree(dir: "tests").include("**/*.java", '**/*.xml', '**/*.html').exclude('**/MoreObjects.java', '**/Preconditions.java')
}
licenseFormat.dependsOn licenseFormatTests

task licenseFormatRes(type: com.hierynomus.gradle.license.tasks.LicenseFormat) {
    source = fileTree(dir: "res").include("**/*.java", '**/*.xml', '**/*.html').exclude('**/MoreObjects.java', '**/Preconditions.java')
}
licenseFormat.dependsOn licenseFormatRes
