apply plugin: 'com.android.library'

android {
    compileSdkVersion 31

    defaultConfig {
        minSdkVersion 16
        versionCode 1300
        versionName "13.0"
    }

    // 使用 JDK 1.8
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        // 剔除这个包下的所有文件（不会移除签名信息）
        exclude 'META-INF/*******'
    }

    android.libraryVariants.configureEach { variant ->
        // aar 输出文件名配置
        variant.outputs.configureEach { output ->
            outputFileName = "${rootProject.name}-${android.defaultConfig.versionName}.aar"
        }
    }
}

afterEvaluate {
    // 排除 BuildConfig.class 和 R.class
    generateReleaseBuildConfig.enabled = false
    generateDebugBuildConfig.enabled = false
    generateReleaseResValues.enabled = false
    generateDebugResValues.enabled = false
}

dependencies {
    // noinspection GradleDependency
    implementation 'com.squareup.okhttp3:okhttp:3.12.13'
    // noinspection GradleDependency
    implementation 'androidx.lifecycle:lifecycle-common:2.1.0'
    // noinspection GradleDependency
    implementation 'androidx.lifecycle:lifecycle-runtime:2.1.0'
}

tasks.withType(Javadoc).configureEach {
    options.addStringOption('Xdoclint:none', '-quiet')
    options.addStringOption('encoding', 'UTF-8')
    options.addStringOption('charSet', 'UTF-8')
}

tasks.register('sourcesJar', Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

tasks.register('javadoc', Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

tasks.register('javadocJar', Jar) {
    dependsOn javadoc
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}