build.gradle 1.68 KB
plugins {
    id 'com.android.library'
}

android {
    compileSdkVersion 31

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 4
        versionName "1.0.4"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    android.libraryVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${project.name}_v" + android.defaultConfig.versionName + '_sdk.jar'
        }
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.3.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

task makeJar(type: Copy) {
    def outAar = "${project.name}_v" + android.defaultConfig.versionName + "_sdk.jar"
    //删除存在的
    delete 'build/libs/'+outAar
    //设置拷贝的文件
    from('build/intermediates/aar_main_jar/release/')
    //打进jar包后的文件目录
    into('build/libs/')
    //将classes.jar放入build/libs/目录下
    //include ,exclude参数来设置过滤
    //(我们只关心classes.jar这个文件)
    include('classes.jar')
    //重命名
    rename ('classes.jar', outAar)
}

makeJar.dependsOn(build)