apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'

apply from: 'version.gradle'
apply from: 'dependencyVersions.gradle'

buildscript {
    repositories {
        jcenter()
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6'
    }
}

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 28
        versionCode buildVersionCode()
        versionName buildVersionName()
        buildConfigField "int", "PLATFORM_VERSION",  getReleaseVersionNumber()
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }

    lintOptions {
        warning "MissingTranslation"
    }

    sourceSets {
        main {
            java {
                srcDir '../../third_party/jsyn'
                srcDir 'src/api/wireapi/java'
            }
            proto {
                srcDir 'src/main/proto'
            }
            aidl {
                srcDir 'src/api/wireapi/aidl'
            }
        }
        String sharedTestDir = 'src/sharedTest/java'
        test {
            java.srcDir sharedTestDir
            java.srcDir 'src/robolectricTest/java'
            java.srcDir 'src/test/java'
        }
        androidTest {
            java.srcDir sharedTestDir
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }


    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}

sourceSets {
    main.java.srcDirs += "${protobuf.generatedFilesBaseDir}/main/javalite"
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.0.0-alpha-3'
    }
    plugins {
        javalite {
            artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                remove java
            }
            task.plugins {
                javalite {}
            }
        }
    }
}

dependencies {
    androidTestImplementation("junit:junit:$junitVersion") {
        exclude module: 'hamcrest-core'
    }

    annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"

    debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"

    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.material:material:1.1.0-alpha04'
    implementation 'com.bignerdranch.android:expandablerecyclerview:2.1.1'
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
    implementation "com.github.bumptech.glide:glide:$glideVersion"
    implementation('com.google.api-client:google-api-client-android:1.25.0') {
        // Avoid error "Program type already present: com.google.common.annotations.Beta".
        exclude group: 'com.google.guava'
        // Avoid error "Program type already present: javax.annotation.CheckForNull"
        exclude group: 'com.google.code.findbugs'
        // Avoid error "Program type already present: com.google.j2objc.annotations.AutoreleasePool"
        exclude group: 'com.google.j2objc'
    }
    implementation 'com.google.ar:core:1.9.0'
    implementation "com.google.ar.sceneform.ux:sceneform-ux:1.9.0"
    implementation "com.google.dagger:dagger:$daggerVersion"
    implementation("com.google.guava:guava:$guavaVersion") {
        // Avoid error "Program type already present: javax.annotation.CheckForNull"
        exclude group: 'com.google.code.findbugs'
        // Avoid error "Program type already present: org.checkerframework.checker.nullness.compatqual.NullableType"
        exclude group: 'org.checkerframework'
        // Avoid error "Program type already present: com.google.j2objc.annotations.AutoreleasePool"
        exclude group: 'com.google.j2objc'
        // Avoid error "Program type already present: org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement"
        exclude group: 'org.codehaus.mojo'
    }
    implementation 'com.google.protobuf:protobuf-lite:3.0.0'
    // Depend on jsyn maven repo.
    implementation 'com.jsyn:jsyn:20170815'
    implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.3'
    implementation 'joda-time:joda-time:2.9.9'
    implementation 'org.joda:joda-convert:1.8'

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation project(':scalarinputapi')

    releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"

    testImplementation "junit:junit:$junitVersion"

    testImplementation("org.robolectric:robolectric:$robolectricVersion") {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
}
