import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.api.LibraryVariant
import com.google.common.base.Joiner

apply plugin: 'com.android.library'

android {
    compileSdkVersion VERSION_COMPILE_SDK
    buildToolsVersion VERSION_BUILD_TOOLS

    defaultConfig {
        minSdkVersion VERSION_MIN_SDK
        targetSdkVersion VERSION_TARGET_SDK
        versionCode 1
        versionName "1.0.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility SOURCE_COMPATIBILITY
    }
    lintOptions {
        abortOnError false
    }
}

repositories {
    mavenCentral()
    jcenter()
}

final String projectAndroidStub = ':AndroidStub'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    provided project(projectAndroidStub)

    testCompile 'junit:junit:4.12'
}

// Using Stub classes first when compiling.
afterEvaluate {
    project.android.libraryVariants.each { LibraryVariant variant ->
        variant.javaCompile.doFirst { JavaCompile javaCompile ->
            String projectAndroidStubPath = project.project(projectAndroidStub).projectDir.canonicalPath
//            println "projectAndroidStubPath: ${projectAndroidStubPath}"
            File stubPath = javaCompile.classpath.find {
                it.canonicalPath.startsWith(projectAndroidStubPath)
            }
            if (stubPath == null) {
                throw new RuntimeException("reset bootclasspath error.")
            }
            javaCompile.options.setBootClasspath(Joiner.on(File.pathSeparator).join(stubPath, javaCompile.options.bootClasspath))
        }
    }
}

apply from: 'upload.gradle'
