AndroidStudio项目导出成jar包

前言:怕忘了,记录一下,后边有用。

1.将文件的plugin改为apply plugin: ‘com.android.library’,或者开始就创建library项目。
2.build.gradle中添加

task makeJar(dependsOn: ['compileReleaseJavaWithJavac'], type: Jar) {
    delete 'build/libs/yourname1.jar'
    delete 'build/libs/yourname2.jar'
    appendix = "demo"
    baseName = "androidJar"
    version = "1.0.0"
    classifier = "release"
    //后缀名
    extension = "jar"
    //最终的 Jar 包名,如果没设置,默认为 [baseName]-[appendix]-[version]-[classifier].[extension]
    archiveName = "yourname1.jar"
    //需打包的资源所在的路径集
    def srcClassDir = [project.buildDir.absolutePath + "/intermediates/classes/release"];
    //初始化资源路径集
    from srcClassDir
    //去除路径集下部分的资源
    exclude "okhttphelper/clz/com/okhttphelper/BuildConfig.class"
    exclude "**/R.class"
    exclude "**/R\$*.class"
    //只导入资源路径集下的部分资源
    include "okhttphelper/clz/com/okhttphelper/**/*.class"

}

task proguard(type: ProGuardTask, dependsOn: makeJar) {
//  输入路径
    injars "build/libs/yourname1.jar"
//  输出路径
    outjars 'build/libs/yourname2.jar'
//  添加配置信息
    configuration 'proguard-rules.pro'
}

3.Termial中输入gradlew makejar,等待
4.\build\libs的路径下生成yourname*.jar

你可能感兴趣的:(android,studio)