Android项目打成jar包

1、主工程依赖library

2、在library中的build.gradle文件中进行配置

def SDK_BASENAME = "idcardcamera";
def SDK_VERSION = "_v1.0";
def OUTPUT_PATH = "build";
def INPUT_PATH = file('build/intermediates/packaged-classes/release/classes.jar')

//删除任务
task deleteBuild(type: Delete) {
    delete OUTPUT_PATH + SDK_BASENAME + SDK_VERSION + ".jar"
}
//创建任务
task makeJar(type: Jar) {
    //需要打包的原始classes.jar
    from zipTree(INPUT_PATH)
    //将assets目录打入jar包
    from fileTree(dir: 'src/main',include: ['assets/**'])
    from fileTree(dir: 'src/main',include: ['res/**'])
    from fileTree(dir: 'src/main',include: ['AndroidManifest.xml'])
    //去掉不需要打包的目录和文件
    exclude('test/', 'BuildConfig.class')
    //生成文件名字
    baseName = SDK_BASENAME + SDK_VERSION
    //生成
    destinationDir = file(OUTPUT_PATH)
}

makeJar.dependsOn(deleteBuild, build)

 

3、点击gradle/library/other/makeJar,生成jar包

你可能感兴趣的:(Android项目打jar包)